start page | rating of books | rating of authors | reviews | copyrights

Programming PHPProgramming PHPSearch this book

1.3. Installing PHP

PHP is available for many operating systems and platforms. The most common setup, however, is to use PHP as a module for the Apache web server on a Unix machine. This section briefly describes how to install Apache with PHP. If you're interested in running PHP on Windows, see Chapter 15, which explains your many options.

To install Apache with PHP, you'll need a Unix machine with an ANSI-compliant C compiler, and around 5 MB of available disk space for source and object files. You'll also need Internet access to fetch the source code for PHP and Apache.

Start by downloading the source distributions of PHP and Apache. The latest files are always available from http://www.php.net and http://www.apache.org, respectively. Store the files in the same directory, so that you have:

-rw-r--r--   1 gnat  wheel  2177983 Oct  9 09:34 apache_1.3.22.tar.gz 
-rw-r--r--   1 gnat  wheel  3371385 Dec 10 14:29 php-4.1.1.tar.gz

Now uncompress and extract the distributions:

# gunzip -c apache_1.3.22.tar.gz | tar xf -
# gunzip -c php-4.1.1.tar.gz | tar xf -

Each distribution unpacks into its own subdirectory, as follows:

drwxr-xr-x   8 gnat  wheel      512 Dec 16 11:26 apache_1.3.22
drwxr-xr-x  16 gnat  wheel     2048 Dec 21 23:48 php-4.1.1

The next step is to configure Apache, then configure PHP, telling it where the Apache source is and specifying the various other features that you want built into PHP. You'll probably want to customize the configurations of Apache and PHP. For instance, provide the --prefix=/some/path option to Apache's configure to change where Apache expects its configuration files and utilities. Similarly, typical options for PHP include --with-apache to identify the location of the Apache source tree, --enable-inline-optimizations to enable compilation options that give a faster PHP interpreter, and --with-mysql to identify where MySQL was installed. Each configuration creates detailed output as it goes:

# cd apache_1.3.22
# ./configure --prefix=/usr/local/apache
Configuring for Apache, Version 1.3.22
 + using installation path layout: Apache (config.layout)
Creating Makefile
Creating Configuration.apaci in src
Creating Makefile in src
 + configured for FreeBSD 4.2 platform
 + setting C compiler to gcc
...
# cd ../php-4.1.1
# ./configure --with-apache=../apache_1.3.22 --enable-inline-optimization \
  --with-mysql=/usr
creating cache ./config.cache
checking for a BSD compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets ${MAKE}... yes
checking for working aclocal... missing
checking for working autoconf... found
checking for working automake... missing
checking for working autoheader... found
checking for working makeinfo... found
Updated php_version.h
...

For a full list of available configure options for each package, see the output of:

./configure --help

Now you can build and install PHP:

# make
# make install

These commands also install the PEAR libraries and copy the compiled Apache module to the Apache source tree.

Finally, change directory back to the Apache directory. Reconfigure Apache, telling it about the newly built PHP module, and compile and install it:

# cd ../apache_1.3.22
# ./configure --prefix=/usr/local/apache --activate-module=src/modules/php4/libphp4.a
# make
# make install

You now have Apache installed in /usr/local/apache, with PHP enabled. You also have PHP's extensions installed (probably in /usr/local/lib/php). You still need to configure the web server to process .php pages with the PHP interpreter, and start the web server. You may also want to change the PHP configuration.

Note that if you already have Apache installed and running on your server, it is possible to add PHP to the existing Apache instance without recompiling it. These days, this is actually the most common way to build PHP. Instead of using --with-apache on your configure line, use --with-apxs. You don't need the Apache source code in this case; only the apxs script needs to be available on your server. Most Linux distributions include this script and the corresponding files in their apache-devel packages.

PHP's configuration goes in a file called php.ini. The settings in this file control the behavior of PHP features, such as session handling and form processing. Later chapters will refer to php.ini options, but in general the code in this book does not require a customized configuration. See http://www.php.net/manual/en/configuration.php for more information on php.ini configuration.

Once you have a web server, you'll need to tell it that .php files are to be handled by the PHP module. Put this in Apache's httpd.conf file, and restart the web server:

AddType application/x-httpd-php .php

The PHP and Apache source directories both include files called INSTALL that contain detailed instructions on troubleshooting and building those programs. If you want a nonstandard installation, or if you encounter problems with the instructions presented here, be sure to read the INSTALL files.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.