PHP can be run on multiple platforms and it can interact with various Web servers. However, the most widespread Web servers are Apache and Microsoft's IIS. In this section you will see how PHP can be compiled in combination with Apache. 2.2.1 Installing Apache with PHP on UnixInstalling Apache with PHP on Unix is not difficult. In contrast to installing binary packages, installing the sources has some advantages. The biggest advantage is most likely that you know exactly which flags have been enabled and which components have been compiled into your binaries. If you are planning to modify the core of Apache or PHP, you have to compile the source code; otherwise, there is no way to make the changes in your binaries. One disadvantage is that it is a lot more work to install sources than to install binaries. An additional disadvantage is that you will most likely not have the knowledge of an experienced Linux or Unix distributor. In case of security problems or any other problems with a software package, your distributor will most likely know what to do best to get around a problem. No matter what you like best in this section, you will learn to compile and to install the source distribution of Apache and PHP. The first thing you have to do is to download the sources of Apache and PHP. Check out your local mirror sites or go to www.apache.org (for Apache) and www.php.net (for PHP). On Unix machines the source code is usually stored in /usr/src. In this scenario we generate a directory called apache_php located in /usr/src. This directory will contain the sources of Apache and PHP as well as a shell script for compiling the sources. Download the sources to /usr/src/apache_php and extract the two packages using tar xvfz packname (for Linux; on other systems consider using tar -xvfz packname; Linux supports both statements) where packname is the name of a package (for example, apache_1.3.22.tar.gz). In the next step you can create two softlinks for making the script you are going to write more independently from the version of Apache and PHP being compiled. This can easily be done using ln: [root@duron apache_php]# ln -s apache_1.3.22/ apache [root@duron apache_php]# ln -s php-4.1.0/ php If no errors occurred, two softlinks have been created that do not contain the version number of the two packages. 2.2.1.1 Configuring ApacheBefore you see how to compile Apache and PHP as a team, it is time to take a closer look at the configuration parameters supported by Apache (in this case Apache 1.3.22). Enter the directory called apache and type ./configure --help as shown in the next listing: [root@duron apache]# ./configure --help [hang on a moment, generating help] Usage: configure [options] Options: [defaults in brackets after descriptions] General options: --quiet, --silent do not print messages --verbose, -v print even more messages --shadow[=DIR] switch to a shadow tree (under DIR) for building Stand-alone options: --help, -h print this message --show-layout print installation path layout (check and debug) Installation layout options: --with-layout=[F:]ID use installation path layout ID (from file F) --target=TARGET install name-associated files using basename TARGET --prefix=PREFIX install architecture-independent files in PREFIX --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX --bindir=DIR install user executables in DIR --sbindir=DIR install sysadmin executables in DIR --libexecdir=DIR install program executables in DIR --mandir=DIR install manual pages in DIR --sysconfdir=DIR install configuration files in DIR --datadir=DIR install read-only data files in DIR --iconsdir=DIR install read-only icon files in DIR --htdocsdir=DIR install read-only welcome pages in DIR --manualdir=DIR install read-only on-line documentation in DIR --cgidir=DIR install read-only cgi files in DIR --includedir=DIR install includes files in DIR --localstatedir=DIR install modifiable data files in DIR --runtimedir=DIR install runtime data in DIR --logfiledir=DIR install logfile data in DIR --proxycachedir=DIR install proxy cache data in DIR Configuration options: --enable-rule=NAME enable a particular Rule named 'NAME' --disable-rule=NAME disable a particular Rule named 'NAME' [DEV_RANDOM=default EXPAT=default IRIXN32=yes ] [IRIXNIS=no PARANOID=no SHARED_CHAIN=de] [SHARED_CORE=default SOCKS4=no SOCKS5=no ] [WANTHSREGEX=default ] --add-module=FILE on-the-fly copy & activate a 3rd-party Module --activate-module=FILE on-the-fly activate existing 3rd-party Module --permute-module=N1:N2 on-the-fly permute module 'N1' with module 'N2' --enable-module=NAME enable a particular Module named 'NAME' --disable-module=NAME disable a particular Module named 'NAME' [access=yes actions=yes alias=yes ] [asis=yes auth_anon=no auth_dbm=no ] [auth_db=no auth_digest=no auth=yes ] [autoindex=yes cern_meta=no cgi=yes ] [digest=no dir=yes env=yes ] [example=no expires=no headers=no ] [imap=yes include=yes info=no ] [log_agent=no log_config=yes log_referer=no ] [mime_magic=no mime=yes mmap_static=no ] [negotiation=yes proxy=no rewrite=no ] [setenvif=yes so=no speling=no ] [status=yes unique_id=no userdir=yes ] [usertrack=no vhost_alias=no ] --enable-shared=NAME enable build of Module named 'NAME' as a DSO --disable-shared=NAME disable build of Module named 'NAME' as a DSO --with-perl=FILE path to the optional Perl interpreter --with-port=PORT set the port number for httpd.conf --without-support disable the build and installation of support tools --without-confadjust disable the user/situation adjustments in config --without-execstrip disable the stripping of executables on installation --server-uid=UID set the user ID the web server should run as [nobody] --server-gid=GID set the group ID the web server UID is a memeber of [#-1] suEXEC options: --enable-suexec enable the suEXEC feature --suexec-caller=NAME set the suEXEC username of the allowed caller [www] --suexec-docroot=DIR set the suEXEC root directory [PREFIX/share/htdocs] --suexec-logfile=FILE set the suEXEC logfile [PREFIX/var/log/suexec_log] --suexec-userdir=DIR set the suEXEC user subdirectory [public_html] --suexec-uidmin=UID set the suEXEC minimal allowed UID [100] --suexec-gidmin=GID set the suEXEC minimal allowed GID [100] --suexec-safepath=PATH set the suEXEC safe PATH [/usr/local/bin:/usr/bin:/bin] --suexec-umask=UMASK set the umask for the suEXEC'd script [server's umask] Deprecated options: --layout backward compat only: use --show-layout --compat backward compat only: use --with-layout=Apache As you can see, the list of configuration parameters provided by Apache seems endless. The following list describes the most important of these parameters. For a complete reference of all flags, check out Apache's documentation:
2.2.1.2 Configuring PHPNow that you have seen how to configure Apache, it is time to take a closer look at PHP. As you have already seen, PHP is not included in Apache's core distribution. PHP is an external yet powerful module that has to be configured independently. In this section you will take a closer look at PHP's configuration parameters in detail. Again, the most important flags will be explained in detail. After you have extracted the sources of PHP and entered the directory containing the sources, you can use ./configure --help to get a list of all configuration parameters of PHP (PHP 4.1): [root@duron php]# ./configure --help Usage: configure [options] [host] Options: [defaults in brackets after descriptions] Configuration: --cache-file=FILE cache test results in FILE --help print this message --no-create do not create output files --quiet, --silent do not print `checking...' messages --version print the version of autoconf that created configure Directory and file names: --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [same as prefix] --bindir=DIR user executables in DIR [EPREFIX/bin] --sbindir=DIR system admin executables in DIR [EPREFIX/sbin] --libexecdir=DIR program executables in DIR [EPREFIX/libexec] --datadir=DIR read-only architecture-independent data in DIR [PREFIX/share] --sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data in DIR [PREFIX/com] --localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var] --libdir=DIR object code libraries in DIR [EPREFIX/lib] --includedir=DIR C header files in DIR [PREFIX/include] --oldincludedir=DIR C header files for non-gcc in DIR [/usr/include] --infodir=DIR info documentation in DIR [PREFIX/info] --mandir=DIR man documentation in DIR [PREFIX/man] --srcdir=DIR find the sources in DIR [configure dir or ..] --program-prefix=PREFIX prepend PREFIX to installed program names --program-suffix=SUFFIX append SUFFIX to installed program names --program-transform-name=PROGRAM run sed PROGRAM on installed program names Host type: --build=BUILD configure for building on BUILD [BUILD=HOST] --host=HOST configure for HOST [guessed] --target=TARGET configure for TARGET [TARGET=HOST] Features and packages: --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --x-includes=DIR X include files are in DIR --x-libraries=DIR X library files are in DIR --enable and --with options recognized: --enable-maintainer-mode enable make rules and dependencies not useful (and sometimes confusing) to the casual installer --with-aolserver=DIR Specify path to the installed AOLserver --with-apxs[=FILE] Build shared Apache module. FILE is the optional pathname to the Apache apxs tool; defaults to apxs. --with-apache[=DIR] Build Apache module. DIR is the top-level Apache build directory, defaults to /usr/local/apache. --with-mod_charset Enable transfer tables for mod_charset (Rus Apache). --with-apxs2[=FILE] Build shared Apache 2.0 module. FILE is the optional pathname to the Apache apxs tool; defaults to apxs. --with-caudium=DIR Build PHP as a Pike module for use with Caudium DIR is the Caudium server dir, with the default value /usr/local/caudium/server. --enable-force-cgi-redirect Enable the security check for internal server redirects. You should use this if you are running the CGI version with Apache. --enable-discard-path If this is enabled, the PHP CGI binary can safely be placed outside of the web tree and people will not be able to circumvent .htaccess security. --with-fhttpd[=DIR] Build fhttpd module. DIR is the fhttpd sources directory, defaults to /usr/local/src/fhttpd. --with-fastcgi=SRCDIR Build PHP as FastCGI application --with-isapi=DIR Build PHP as an ISAPI module for use with Zeus. --with-nsapi=DIR Specify path to the installed Netscape --with-phttpd=DIR --with-pi3web=DIR Build PHP as a module for use with Pi3Web. --with-roxen=DIR Build PHP as a Pike module. DIR is the base Roxen directory, normally /usr/local/roxen/server. --enable-roxen-zts Build the Roxen module using Zend Thread Safety. --with-servlet[=DIR] Include servlet support. DIR is the base install directory for the JSDK. This SAPI prereqs the java extension must be built as a shared dl. --with-thttpd=SRCDIR Build PHP as thttpd module --with-tux=MODULEDIR Build PHP as a TUX module (Linux only) --enable-debug Compile with debugging symbols. --with-layout=TYPE Sets how installed files will be laid out. Type is one of PHP (default) or GNU --with-config-file-path=PATH Sets the path in which to look for php.ini, defaults to PREFIX/lib --with-pear=DIR Install PEAR in DIR (default PREFIX/lib/php) --without-pear Do not install PEAR --enable-safe-mode Enable safe mode by default. --with-exec-dir[=DIR] Only allow executables in DIR when in safe mode defaults to /usr/local/php/bin --with-openssl[=DIR] Include OpenSSL support (requires OpenSSL >= 0.9.5) --enable-sigchild Enable PHP's own SIGCHLD handler. --enable-magic-quotes Enable magic quotes by default. --disable-rpath Disable passing additional runtime library search paths --enable-libgcc Enable explicitly linking against libgcc --disable-short-tags Disable the short-form <? start tag by default. --enable-dmalloc Enable dmalloc --enable-php-streams Include experimental php streams. Do not use unless you are testing the code! --with-zlib-dir=<DIR> Define the location of zlib install directory --with-zlib[=DIR] Include zlib support (requires zlib >= 1.0.9). DIR is the zlib install directory. --with-aspell[=DIR] Include ASPELL support. --enable-bcmath Enable bc style precision math functions. --with-bz2[=DIR] Include BZip2 support --enable-calendar Enable support for calendar conversion --with-ccvs[=DIR] Include CCVS support --with-cpdflib[=DIR] Include cpdflib support (requires cpdflib >= 2). DIR is the cpdfllib install directory, defaults to /usr. --with-jpeg-dir[=DIR] jpeg dir for cpdflib 2.x --with-tiff-dir[=DIR] tiff dir for cpdflib 2.x --with-crack[=DIR] Include crack support. --enable-ctype Enable ctype support --with-curl[=DIR] Include CURL support --with-cybercash[=DIR] Include CyberCash support. DIR is the CyberCash MCK install directory. --with-cybermut[=DIR] Include CyberMut (french Credit Mutuel telepaiement) --with-cyrus Include cyrus imap support --with-db Include old xDBM support (deprecated) --enable-dba=shared Build DBA as a shared module --with-gdbm[=DIR] Include GDBM support --with-ndbm[=DIR] Include NDBM support --with-db2[=DIR] Include Berkeley DB2 support --with-db3[=DIR] Include Berkeley DB3 support --with-dbm[=DIR] Include DBM support --with-cdb[=DIR] Include CDB support --enable-dbase Enable the bundled dbase library --with-dbplus Include dbplus support --enable-dbx Enable dbx --with-dom[=DIR] Include DOM support (requires libxml >= 2.4.2). DIR is the libxml install directory, defaults to /usr. --enable-exif Enable exif support --with-fbsql[=DIR] Include FrontBase support. DIR is the FrontBase base directory. --with-fdftk[=DIR] Include fdftk support --enable-filepro Enable the bundled read-only filePro support --with-fribidi[=DIR] Include fribidi support (requires FriBidi >=0.1.12). DIR is the fribidi installation directory - default /usr/local/ --enable-ftp Enable FTP support --with-gd[=DIR] Include GD support (DIR is GD's install dir). Set DIR to shared to build as a dl, or shared,DIR to build as a dl and still specify DIR. --enable-gd-native-ttf GD: Enable TrueType string function in gd --with-jpeg-dir=DIR GD: Set the path to libjpeg install prefix. --with-png-dir=DIR GD: Set the path to libpng install prefix. --with-xpm-dir=DIR GD: Set the path to libXpm install prefix. --with-freetype-dir=DIR GD: Set the path to freetype2 install prefix. --with-ttf[=DIR] GD: Include FreeType 1.x support --with-t1lib[=DIR] GD: Include T1lib support. --with-gettext[=DIR] Include GNU gettext support. DIR is the gettext install directory, defaults to /usr/local --with-gmp Include gmp support --with-hyperwave Include Hyperwave support --with-icap[=DIR] Include ICAP support. --with-iconv[=DIR] Include iconv support --with-imap[=DIR] Include IMAP support. DIR is the c-client install prefix. --with-kerberos[=DIR] IMAP: Include Kerberos support. DIR is the Kerberos install dir. --with-imap-ssl[=DIR] IMAP: Include SSL support. DIR is the OpenSSL install dir. --with-informix[=DIR] Include Informix support. DIR is the Informix base install directory, defaults to nothing. --with-ingres[=DIR] Include Ingres II support. DIR is the Ingres base directory (default /II/ingres) --with-interbase[=DIR] Include InterBase support. DIR is the InterBase base install directory, defaults to /usr/interbase --with-ircg-config Path to the ircg-config script --with-ircg Include ircg support --with-java[=DIR] Include Java support. DIR is the base install directory for the JDK. This extension can only be built as a shared dl. --with-ldap[=DIR] Include LDAP support. DIR is the LDAP base install directory. --enable-mailparse Enable mailparse support --enable-mbstring Enable multibyte string support --enable-mbstr-enc-trans Enable japanese encoding translation --with-mcal[=DIR] Include MCAL support. --with-mcrypt[=DIR] Include mcrypt support. DIR is the mcrypt install directory. --with-mhash[=DIR] Include mhash support. DIR is the mhash install directory. --with-ming[=DIR] Include ming support --with-mnogosearch[=DIR] Include mnoGoSearch support. DIR is the mnoGoSearch base install directory, defaults to /usr/local/mnogosearch. --with-msql[=DIR] Include mSQL support. DIR is the mSQL base install directory, defaults to /usr/local/Hughes. --with-muscat[=DIR] Include muscat support. --with-mysql[=DIR] Include MySQL support. DIR is the MySQL base directory. If unspecified, the bundled MySQL library will be used. --with-ncurses Include ncurses support --with-oci8[=DIR] Include Oracle-oci8 support. Default DIR is ORACLE_HOME. --with-adabas[=DIR] Include Adabas D support. DIR is the Adabas base install directory, defaults to /usr/local. --with-sapdb[=DIR] Include SAP DB support. DIR is SAP DB base install directory, defaults to /usr/local. --with-solid[=DIR] Include Solid support. DIR is the Solid base install directory, defaults to /usr/local/solid --with-ibm-db2[=DIR] Include IBM DB2 support. DIR is the DB2 base install directory, defaults to /home/db2inst1/sqllib --with-empress[=DIR] Include Empress support. DIR is the Empress base install directory, defaults to $EMPRESSPATH. From PHP4, this option only supports Empress Version 8.60 and above --with-empress-bcs[=DIR] Include Empress Local Access support. DIR is the Empress base install directory, defaults to $EMPRESSPATH. From PHP4, this option only supports Empress Version 8.60 and above. --with-velocis[=DIR] Include Velocis support. DIR is the Velocis base install directory, defaults to /usr/local/velocis. --with-custom-odbc[=DIR] Include a user defined ODBC support. The DIR is ODBC install base directory, which defaults to /usr/local. Make sure to define CUSTOM_ODBC_LIBS and have some odbc.h in your include dirs. E.g., you should define following for Sybase SQL Anywhere 5.5.00 on QNX, prior to run configure script: CPPFLAGS="-DODBC_QNX -DSQLANY_BUG" LDFLAGS=-lunix CUSTOM_ODBC_LIBS="-ldblib -lodbc". --with-iodbc[=DIR] Include iODBC support. DIR is the iODBC base install directory, defaults to /usr/local. --with-esoob[=DIR] Include Easysoft OOB support. DIR is the OOB base install directory, defaults to /usr/local/easysoft/oob/client. --with-unixODBC[=DIR] Include unixODBC support. DIR is the unixODBC base install directory, defaults to /usr/local. --with-openlink[=DIR] Include OpenLink ODBC support. DIR is the OpenLink base install directory, defaults to /usr/local. This is the same as iODBC. --with-dbmaker[=DIR] Include DBMaker support. DIR is the DBMaker base install directory, defaults to where the latest version of DBMaker is installed (such as /home/dbmaker/3.6). --with-oracle[=DIR] Include Oracle-oci7 support. Default DIR is ORACLE_HOME. --with-ovrimos[=DIR] Include Ovrimos SQL Server support. DIR is the Ovrimos' libsqlcli install directory. --enable-pcntl Enable experimental pcntl support (CGI ONLY!) --without-pcre-regex Do not include Perl Compatible Regular Expressions support. Use --with-pcre-regex=DIR to specify DIR where PCRE's include and library files are located, if not using bundled library. --with-pdflib[=DIR] Include PDFlib support. DIR is the pdflib base install directory, defaults to /usr/local Set DIR to shared to build as dl, or shared,DIR to build as dl and still specify DIR. --with-jpeg-dir[=DIR] PDFLIB: define libjpeg install directory --with-png-dir[=DIR] PDFLIB: define libpng install directory --with-tiff-dir[=DIR] PDFLIB: define libtiff install directory --with-pfpro[=DIR] Include Verisign Payflow Pro support --with-pgsql[=DIR] Include PostgreSQL support. DIR is the PostgreSQL base install directory, defaults to /usr/local/pgsql. Set DIR to shared to build as a dl, or shared,DIR to build as a dl and still specify DIR. --disable-posix Disable POSIX-like functions --with-pspell[=DIR] Include PSPELL support. --with-qtdom Include QtDOM support (requires Qt >= 2.2.0). --with-libedit[=DIR] Include libedit readline replacement. --with-readline[=DIR] Include readline support. DIR is the readline install directory. --with-recode[=DIR] Include recode support. DIR is the recode install directory. --with-satellite[=DIR] Enable CORBA support via Satellite (EXPERIMENTIAL) DIR is the base directory for ORBit --with-mm[=DIR] Include mm support for session storage --enable-trans-sid Enable transparent session id propagation --disable-session Disable session support --enable-shmop Enable shmop support --with-snmp[=DIR] Include SNMP support. DIR is the SNMP base install directory, defaults to searching through a number of common locations for the snmp install. Set DIR to shared to build as a dl, or shared,DIR to build as a dl and still specify DIR. --enable-ucd-snmp-hack Enable UCD SNMP hack --enable-sockets Enable sockets support --with-regex=TYPE regex library type: system, apache, php --with-system-regex (deprecated) Use system regex library --with-swf[=DIR] Include swf support --with-sybase[=DIR] Include Sybase-DB support. DIR is the Sybase home directory, defaults to /home/sybase. --with-sybase-ct[=DIR] Include Sybase-CT support. DIR is the Sybase home directory. Defaults to /home/sybase. --enable-sysvsem Enable System V semaphore support. --enable-sysvshm Enable the System V shared memory support --with-vpopmail[=DIR] Include vpopmail support. --enable-wddx Enable WDDX support --disable-xml Disable XML support using bundled expat lib --with-expat-dir=DIR XML: external libexpat install dir --with-xmlrpc[=DIR] Include XMLRPC-EPI support --with-expat-dir=DIR XMLRPC-EPI: libexpat dir for XMLRPC-EPI --enable-xslt Enable xslt support --with-xslt-sablot XSLT: Enable the sablotron backend --with-expat-dir=DIR Sablotron: libexpat dir for Sablotron 0.50 --with-yaz[=DIR] Include YAZ support (ANSI/NISO Z39.50). DIR is the YAZ bin install directory --enable-yp Include YP support --with-zip[=DIR] Include zip support (requires zziplib >= 0.10.6). DIR is the zziplib install directory, default is /usr/local. --enable-versioning Export only required symbols. See INSTALL for more information --enable-experimental-zts This will most likely break your build --enable-inline-optimization If you have much memory and are using gcc, you might try this. --enable-memory-limit Compile with memory limit support. --with-tsrm-pth[=pth-config] Use GNU Pth. --with-tsrm-st --with-tsrm-pthreads Use POSIX threads (default) --enable-shared[=PKGS] build shared libraries [default=yes] --enable-static[=PKGS] build static libraries [default=yes] --enable-fast-install[=PKGS] optimize for fast installation [default=yes] --with-gnu-ld assume the C compiler uses GNU ld [default=no] --disable-libtool-lock avoid locking (might break parallel builds) --with-pic try to use only PIC/non-PIC objects [default=use both] Let's take a detailed look at the most important flags:
If you need additional components such as support for DB2 or Oracle, you just have to use the flags in the listing generated by ./configure --help. 2.2.1.3 Compiling Apache and PHP as a TeamUp to now you have seen which configuration parameters are supported by Apache and PHP. In the next step it is time to compile Apache and PHP as a team. Compiling the code is a crucial point because you have to know which components you are going to use and which components won't be interesting for you. Recall that we have generated a directory called apache_php located in /usr/local. apache_php contains the source code of Apache and PHP as well as two softlinks called apache and php pointing to the directories generated by extracting the tar-archives. Many people install the sources in /usr/local/src or /usr/src. It's up to you where best to install the code. To install Apache and PHP, it is useful to write a small shell script containing all commands needed to configure, generate, and install the binaries. In the next listing you can see a Korn shell script containing everything you need to install the two software packages. Let's take a look: #!/bin/ksh STARTDIR=$PWD APACHEPREFIX=/usr/local/apache print "Installation tool for Apache and PHP" print "Configuring Apache ..." cd apache CFLAGS='-O3 -march=athlon' ./configure --prefix=$APACHEPREFIX \ print "configuring PHP ..." cd ../php CFLAGS='-O3 -march=athlon' ./configure --prefix=$APACHEPREFIX \ --prefix=/usr/local/apache \ --with-apache=../apache \ --with-config-file-path=$APACHEPREFIX/conf \ --enable-ftp \ --enable-gd-native-ttf \ --enable-mailparse \ --enable-mbstring \ --enable-memory-limit \ --enable-sockets \ --enable-sysvsem \ --with-bcmath \ --with-bz2 \ --with-freetype-dir=/usr/include/freetype2/freetype \ --with-gd \ --with-jpeg-dir=/usr/include \ --with-pgsql=/usr/src/postgresql-7.2 \ --with-png-dir=/usr/include \ --with-system-regex \ --with-tiff-dir=/usr/include \ --with-xpm-dir=/usr/include sleep 10 print "building PHP ..." make make install print "configuring and buidling Apache with PHP" cd ../apache CFLAGS='-O3 -march=athlon' \ ./configure --activate-module=src/modules/php4/libphp4.a \ --with-perl=/usr/bin/perl \ --enable-module=php4 make make install print "copying and updating configuration" cd ../php cp php.ini-dist $APACHEPREFIX/conf/php.ini -v if [[ $(egrep -e '^( |\t )*AddType application/x-httpd-php .php' \ $APACHEPREFIX/conf/httpd.conf) = '' ]] then print "AddType not found - adding configuration" print "AddType application/x-httpd-php .php" >> \ $APACHEPREFIX/conf/httpd.conf else print "AddType found - no modifications necessary " fi cd $STARTDIR At the beginning of the script, APACHEPREFIX is defined. This variable contains the location where you want to install Apache. Then you can go to the directory called apache. In this line you can see that it is useful to use a softlink and not the full name of the directory. If the version of your software changes, you can still use the same script and no changes have to be made. After that Apache is configured the first time, configure is called, which generates the makefiles needed to build Apache binaries. In this example, configure is called with some additional parameters that are optional: CFLAGS contains additional flags the C compiler should use to build the binaries. -O3 tells GCC to use the highest level of optimization. -march tells the compiler to optimize the binaries for AMD Athlon machines. Keep in mind that these flags are optional. It is not necessary to use CFLAGS, but in some cases, it can help you achieve minor improvements in speed. After running configure the first time, you can go to the directory containing the PHP sources. There you have to call configure again. In order to build powerful PHP binaries, many flags can be enabled. In this scenario many components of PHP such as support for GD, PostgreSQL, or FreeType are enabled. In most parts of the book we will work with Red Hat 7.2's standard binaries of PHP. In real life most people will work with precompiled binaries, so we have decided to stick to this in most parts of the book. However, in some specific sections such as the section about PDF, we will use self-compiled binaries because the standard binaries do not support the PDF format. In sections where the standard packages of Red Hat are not used, we will mention that the self-compiled binaries have been used. After configuring PHP, the compiler has to be started using make. make builds all binaries, and make install will copy these binaries to the appropriate location. If the binaries have successfully been configured and installed, Apache has to be compiled and a configuration file can be copied to the correct location. In case of PHP 4, this file is called php.ini-dist. Finally the line shown in the next listing has to be added to httpd.conf, which is the file containing the configuration of Apache: AddType application/x-httpd-php .php As you have just learned, this line has to be added to the configuration file. However, this script does not just add this line to the file because this way the line could be added to the file more than once. Therefore the script checks if the line is already in the file, and if so, a message is displayed but no changes are made. Otherwise the line is added to the end of the file. To check if the required line is in the file, egrep is used in combination with a simple regular expression. Before running the shell script, don't forget to generate the directory called apache in /usr/local; otherwise, Apache cannot be installed. Make sure that you add execution rights as shown in the next listing: [root@duron apache_php]# chmod +x compile.sh 2.2.1.4 Starting and Testing ApacheAfter compiling and installing Apache, you can start the daemon. You can go to the directory containing Apache's binaries: [root@duron root]# cd /usr/local/apache/bin/ The command for starting Apache is called apachectl. This command starts various processes that will be used to handle the requests sent to the Web server. To find out how apachectl works, you can use the command shown in the next listing: [root@duron bin]# ./apachectl --help usage: ./apachectl (start|stop|restart|fullstatus|status|graceful|configtest| help) start - start httpd stop - stop httpd restart - restart httpd if running by sending a SIGHUP or start if not running fullstatus - dump a full status screen; requires lynx and mod_status enabled status - dump a short status screen; requires lynx and mod_status enabled graceful - do a graceful restart by sending a SIGUSR1 or start if not running configtest - do a configuration syntax test help - this screen To start Apache, ./apachectl start has to be used: [root@duron bin]# ./apachectl start [Mon Dec 31 01:06:20 2001] [alert] httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName ./apachectl start: httpd started The warning is caused by a wrong default setting of Apache. The warning can easily be avoided by changing the directive ServerName to a useful value such as localhost. After starting the Web server, you can take a look and see if Apache is running. This step is highly recommended because it is the only reliable way to find out if the Web server has really been started successfully: [root@duron bin]# ps ax | grep http 5570 ? S 0:00 /usr/local/apache/bin/httpd 5571 ? S 0:00 /usr/local/apache/bin/httpd 5572 ? S 0:00 /usr/local/apache/bin/httpd 5573 ? S 0:00 /usr/local/apache/bin/httpd 5574 ? S 0:00 /usr/local/apache/bin/httpd 5575 ? S 0:00 /usr/local/apache/bin/httpd 5578 pts/3 S 0:00 grep http Quite a few processes are running. Apache 1.3.x is a so-called preforking server, which means that there are usually spare processes in memory so that every request passed to the Web server can be processed easily. After you have started Apache, you can check whether PHP works correctly. You can go to /usr/local/apache/htdocs and write a simple demo application in PHP: <?php phpinfo() ?> This line will make PHP display a lot of information about the installation. Figure 2.1 shows some information about the current PHP installation. Figure 2.1. Information about the current PHP installation.If information about the desired components is listed, there should not be any problems when working with PHP. If a feature you need is not listed, something has gone wrong during compilation. 2.2.2 Installing the ApacheToolBox on UnixMany people are fed up with installing Apache and a huge set of additional components manually all the time. Just think of the huge number of Apache modules and interfaces that can be installed in combination with Apache. Installing the Web server with support for PHP, mod_perl, Jakarta, Tomcat, and many other packages can be painful and time-consuming. To get around the problem, you can use a product called ApacheToolBox, which can be downloaded from http://www.apachetoolbox.com. Usually this package contains a recent set of all modules that are widely used. After downloading the ApacheToolBox, you can extract the source code by using tar xvfz Apachetoolbox-1.5.50.tar.gz. If no errors occurred, just enter the directory that was created when extracting the directory and run install.sh: [hs@duron Apachetoolbox-1.5.50]$ ./install.sh The script will check some basic settings on your machine and an interactive menu will be displayed. There you can select which components you want to be installed. In Figure 2.2, you can see what the form looks like. Just follow the instructions and Apache will be compiled. Figure 2.2. Installing the ApacheToolBox.2.2.3 Installing Apache with PHP on WindowsInstalling Apache with PHP and PostgreSQL is slightly more difficult than installing it on Unix machines. In this section you will be guided through all the important steps and you will see what has to be done. The first thing is to install Cygwin. This package contains PostgreSQL binaries you will need to run PostgreSQL on Windows. Chapter 6, "Installing PostgreSQL," explains how to install Cygwin. The next thing to do is to install Apache. Just download binaries for Windows from http://www.apache.org/dist/httpd/binaries/win32/ and execute the EXE file. This will start an interactive wizard. Just follow the instructions and Apache will be installed almost automatically. Figure 2.3 shows what the interactive tool looks like. Figure 2.3. Apache's installation at work.After you have successfully installed Apache, it is time to test the Web server. If the installation was successful, Apache is already up and running. Therefore you simply have to access localhost as shown in Figure 2.4. Figure 2.4. Testing Apache.If the HTML page been displayed properly, Apache is up and running. In the next step you can shut down Apache again and you can start installing PHP. Go to your nearest PHP mirror or to www.php.net and download the PHP installer for Windows. Just start the EXE file and you will be guided through the installation as shown in Figure 2.5. Figure 2.5. Installing PHP.After installing PHP, you have to perform some basic modifications that you will need to run PostgreSQL on your Windows box. The first thing do to is to modify your php.ini file. In this file you can find a line like the one in the next listing: ;extension=php_pgsql.dll Remove the leading semicolon and exit the file. After that you have to edit httpd.conf. The following line must be added to the file: AddType application/x-httpd-php .php The only thing that is still missing is the library responsible for interacting with PostgreSQL. This DLL can be found in a WinZip package you can download from www.php.net. Just unzip the file and create a directory called dlls located in the directory where you have installed PHP. Copy the DLL file called php_pgsql.dll to the newly created directory and restart Apache. Now Apache, PHP, and PostgreSQL are running as a team. |