|[ Team LiB ]|
Installing PHP for Linux and Apache
In this section, we will look at one way of installing PHP with Apache on Linux. The process is more or less the same for any Unix operating system. You might be able to find prebuilt versions of PHP for your system, which are simple to install.
Before you install, you should ensure that you are logged in to your system as the root user. If you are not allowed access to your system's root account, you might need to ask your system administrator to install PHP for you.
There are two ways of compiling an Apache PHP module. You can either recompile Apache, statically linking PHP into it, or you can compile PHP as a dynamic shared object (DSO). If your version of Apache was compiled with DSO support, it is capable of supporting new modules without the need for recompiling the server. This method is the easiest way to get PHP up and running, and it is the one we cover in this section.
Where Is Apache?
You should see a list of modules. If you see
among them, you should be able to proceed; otherwise, you might need to recompile Apache. The Apache distribution contains full instructions for this.
Compile Apache with DSO Support
If you have not already done so, you need to download the latest distribution of PHP (PHP 5.0.0b1 at the time of writing). Your distribution will be archived as a tar file and compressed with gzip, so you will need to unpack it:
tar -xvzf php-5.0.0b1.tar.gz
After your distribution is unpacked, you should move to the PHP distribution directory:
Within your distribution directory you will find a script called configure. This accepts additional information that should be provided when the configure script is run from the command line. These command-line arguments control the features that PHP supports. For this example, we will include some useful command-line arguments, although you might want to specify arguments of your own. We will discuss some of the configure options available to you later in the hour:
./configure \ --prefix=/home/usr/local/php5/ \ --with-mysql \ --with-apxs=/usr/local/apache/bin/apxs \ --with-xsl \ --with-gdbm \ --with-gd \ --with-freetype=/usr/include/freetype/ \ --with-zlib-dir=/usr/include \ --with-ttf \ --with-jpeg-dir=/usr/lib
Installing PHP with Apache 2
The directives chosen in this example are designed to support the features discussed in this book. Most of them require that your system has certain libraries installed before you can compile PHP. The configure script will complain if the relevant libraries cannot be located.
Of these configure options, the one that is absolutely essential is --with-apxs because it associates PHP with your server. The argument you use depends on the location of Apache on your server. If you are running Linux and are not sure where to find Apache, try running the locate command at the command line, like so:
It lists all the paths on your system that contain the string apxs.
After the configure script has run, you can run the make program. You need a C compiler on your system to run this command successfully:
make make install
|[ Team LiB ]|