Installing PHP 4.x for Apache 1.x.x on Linux
by Nathan Wallace (Oct 25, 1999)
and John Brett (Dec 4, 2000)
Introduction
This document describes how to install
PHP for
Apache on Linux. It was written using
Red Hat 7.0, Apache 1.3.14 and PHP 4.0.3 patch level 1
You should have Apache installed before trying to install PHP. Here are my Apache installation instructions.
If you want to use PHP with MySQL then you must install MySQL first.
Before we Begin
- These instructions assume that you have Apache installed according to my instructions. That installation is done into /usr/local/etc/httpd and /www.
Getting PHP
- You must be logged in as root to perform this installation.
su root
- You can get PHP4.0.3 patch level 1 from here. Here is a list of mirrors.
Or you can ftp from mirror.aarnet.edu.au
ftp mirror.aarnet.edu.au
cd php
cd distributions
bin
hash
get php-4.0.3pl1.tar.gz
bye
- I save all my downloads in:
/usr/local/downloads
If you don't already have one, you may need to create that directory now:
mkdir /usr/local/downloads
Installing PHP
- We will install PHP in /usr/local/etc, but use a tricky tar command to do it in on hit from the download directory:
cd /usr/local/downloads
tar xzf php-4.0.3pl1.tar.gz -C ../etc
- Now we create a nice directory name (php) for the installed directory (php-4.0.3pl1):
cd /usr/local/etc
ln -s php-4.0.3pl1 php
Compiling PHP
- First let's get where the action is:
cd php
- You now have 3 options:
- Simple PHP install without MySQL - goto step 3
- Simple PHP install with MySQL - goto step 4
- Custom PHP install - goto step 5
- Simple PHP install without MySQL. Next, jump to step 6.
./configure --with-apache=../httpd --with-config-file-path=/www/conf --enable-track-vars
- Simple PHP install with MySQL. MySQL must be installed before you can configure PHP to use it. I recommend that MySQL should always be reachable with /usr/local/mysql. Even if you install it else where you should create a symbolic link from /usr/local/mysql. Otherwise the compiler can have problems finding the mysqlclient library. The command should look like this:
./configure --with-mysql=/usr/local/mysql --with-config-file-path=/www/conf --with-apache=../httpd --enable-track-vars
Next, jump to step 6.
- Custom PHP install. Take a look at the available configuration directives by using this command:
./configure --help
- Now we can make the PHP executable. This may take a while.
make
- Now we install the PHP module with:
make install
Adding the PHP Module to Apache
- Now we have to setup Apache to include the PHP module:
cd ../httpd
- Re-configure Apache to use the PHP module. You should use your previous Apache configure command along with the PHP activate module directive. You can see your previous Apache configure command by doing:
cat config.status
You can configure Apache using the previous command with the added PHP module by doing:
./config.status --activate-module=src/modules/php4/libphp4.a
If you used the simple Apache install from my instructions this will effectively perform this:
./configure --prefix=/usr/local/etc/httpd --sysconfdir=/www/conf \
--activate-module=src/modules/php4/libphp4.a --enable-module=status \
--enable-module=rewrite --enable-module=status
- Make Apache with PHP enabled:
make
- Now shut down Apache and install before starting again:
/usr/local/etc/httpd/bin/apachectl stop
make install
/usr/local/etc/httpd/bin/apachectl start
Setting Up PHP
- PHP has created an ini file. We have to install this into it's correct location.
cd ../php
cp php.ini-dist /www/conf/php.ini
- We have to tell Apache to pass certain file extensions to PHP. We do this in Apache's httpd.conf file.
cd /www/conf
- Edit the httpd.conf file. If you do a search for php you will find a couple of commented out lines telling Apache to use the PHP module. You should uncomment them to look like this.
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
- I prefer to use the extension .phtml, you can use whatever extension you like (even .html) by adding lines to httpd.conf like this:
AddType application/x-httpd-php .phtml
Check that it Works
- We have to restart Apache to make these changes take effect on the running server.
cd /usr/local/etc/httpd/bin
./apachectl restart
- Apache should now be running with PHP enabled. The server version should include PHP/4.0.3pl1.
./apachectl status
Apache Server Status for dev.synop.com
Server Version: Apache/1.3.14 (Unix) PHP/4.0.3pl1
Server Built: Dec 4th 2000 13:31:09
...
- Now it is time to test PHP with a page. The simplest thing to do is create a page in one of your virtual servers (eg: dev.synop.com) called test.php. My file is here (link removed). This file contains the following text:
<?php phpinfo(); ?>
- Point your browser at this file on the virtual host which you used:
http://dev.synop.com/test.php
- The results should look something like this (link removed).