1 TITLE: Apache2+PHP4+Htdig
2 LFS VERSION: 3.1 and up
3 AUTHOR: Marcos Zapata <zeta11@yahoo.com>
6 How to setup PHP4 with Apache2 and ht://Dig.
9 When I first try to compile PHP4 for Apache 2, I couldn't because of the new
10 layered I/O support implemented. I read the README in sapi/apache2filter, but
11 it didn't help and didn't want to go back to apache-1.3.x, so this is how I had
14 You can download apache from http://httpd.apache.org and PHP from
15 http://www.php.net. I'm going to use httpd-2.0.39.tar.gz and php-4.2.1.tar.bz2.
20 #Remember to change '--prefix=' to reflect the layout in your system, I prefer
21 #to use a non-standard location for these packages. If you built LFS, you should
22 #have installed openssl and perl, if not remove these options from configure.
24 tar -zxvf httpd-2.0.39.tar.gz
26 ./configure --prefix=/opt/httpd-2.0.39 --enable-ssl --enable-cgi --enable-so \
27 --enable-modules=all --with-perl --enable-shared=max
31 Check if you have a nobody user defined, if not add it with useradd, something
32 like: 'useradd nobody' should suffice. Now let see if everything went fine:
34 /opt/httpd-2.0.39/bin/apachectl start
36 Use lynx, nmap, netstat or whatever tool you use to see if the server is
37 running. If you have lynx: 'lynx http://localhost/' will give you a page that
38 shows a successfully installation of apache. If you don't have it you could
39 use 'netstat -l | grep www', will show a line similar to this one:
40 'tcp 0 0 *:www *.* LISTEN'
42 Now, that we are sure:
44 /opt/httpd-2.0.39/bin/apachectl stop
46 ,just for a while to install PHP.
51 tar -jxvf php-4.2.1.tar.bz2
54 #PHP gives you tons of options, use the ones that you need. Check them with
55 #'./configure --help'. If you don't have mysql installed, php will build a
56 #built-in module for it. I use the following options:
58 ./configure --prefix=/opt/httpd-2.0.39 \
59 --with-config-file-path=/opt/httpd-2.0.39/conf --without-pear --with-openssl \
60 --with-zlib --with-bz2 --enable-calendar --with-gdbm --with-db3 --with-gmp \
61 --with-mysql --with-ncurses --with-pgsql
65 OK, we have to add some options to /opt/httpd-2.0.39/conf/httpd.conf:
67 echo "ScriptAlias /php/ \"/opt/httpd-2.0.39/bin/\"" >> \
68 /opt/httpd-2.0.39/conf/httpd.conf
69 echo "Action application/x-httpd-php \"/php/php\"" >> \
70 /opt/httpd-2.0.39/conf/httpd.conf
71 echo "AddType application/x-httpd-php .php" >>
72 /opt/httpd-2.0.39/conf/httpd.conf
74 This is vital. Make sure you change /php/ to point to where you installed these
78 echo "<? phpinfo(); ?>" > /opt/httpd-2.0.39/htdocs/test.php
80 It's time to see if everything went fine, restart the server with:
82 /opt/httpd-2.0.39/bin/apachectl start
84 You'l need lynx or another web browser now, with lynx do:
86 lynx http://localhost/test.php
88 This page will show you information about PHP and your system. If you were able
89 to see it, the instalation was successful. You can delete test.php now.
91 Following the LFS style we...:
93 ln -s /opt/httpd-2.0.39 /opt/apache2
95 OK, now we need a boot script, create it with:
97 cat > /etc/rc.d/init.d/apache << "EOF"
100 source /etc/rc.d/init.d/functions
104 echo "Starting web server..."
105 loadproc /opt/apache2/bin/httpd
108 echo "Stopping web server..."
109 killproc /opt/apache2/bin/httpd
117 statusproc /opt/apache2/bin/httpd
120 echo "Usage: $0 {start|stop|restart|status}"
126 chmod a+x /etc/rc.d/init.d/apache
128 Remember to make the symlinks in /etc/rc.d/rc*.d.
133 An interesting package to be used in a web server is htdig, but it was very
134 tricky to install in my LFS. You can download it from http://www.htdig.org.
136 tar -zxvf htdig-3.1.6.tar.gz
139 cp configure configure.bak
140 sed -e "s/ofstream=1/ofstream=0/" configure.bak > configure
142 I had to do this because it didn't recognize my gcc instalation.
143 Edit htlib/htString.h to force it to use iostream.h, comment it like this:
145 // #ifdef HAVE_OSTREAM_H
146 // #include <ostream.h>
148 // #ifdef HAVE_IOSTREAM_H
149 #include <iostream.h>
153 Only leave '#include <iostream.h>' uncommented. Now we won't have any trouble
156 ./configure --prefix=/opt/httpd-2.0.39 \
157 --with-config-dir=/opt/httpd-2.0.39/conf \
158 --with-common=/opt/httpd-2.0.39/common \
159 --with-database-dir=/opt/httpd-2.0.39/db \
160 --with-cgi-bin-dir=/opt/httpd-2.0.39/cgi-bin \
161 --with-image-dir=/opt/httpd-2.0.39/htdocs/htdig \
162 --with-search-dir=/opt/httpd-2.0.39/htdocs/htdig
166 To start using it, you have to edit /opt/apache2/conf/htdig.conf. As an
167 example change 'start_url:' to 'http://localhost/' and run:
168 '/opt/apache2/bin/rundig'.
169 It will take a while to build the search database, you can safely ignore any
170 warning message. To give it a try: 'lynx http://localhost/htdig/search.html'.
172 Voila! We're done. Remember to change all configuration files to reflect your
173 system layout and run 'rundig' again, also to read all documentation. Good luck.