J.5. Part I - Installing PHP4

J.5.1. Step one; Compiling PHP4 as a module for Apache2

First download the latest PHP4 tar-ball from php.net or the closest mirror and unpack it in a temporary directory.

Since we will compile PHP4 ourself we need first to make sure a number of libraries and the corresponding header files are installed in the system in order to be able to compile PHP4. This is done by installing a number of "*-devel.rpm" on your server. Depending your wanted configuration different development libraries must be made available.

At the very minimum you will need the "apache2-devel.rpm" which provides the "/sbin/apxs2" (Apache eXtenSion 2) command used to build modules with Apache2. Other modules you might need are

  • jpeg-devel.rpm

  • png-devel.rpm

  • mm-devel.rpm

  • xml2-devel.rpm

  • mysql-devel.rpm

  • ...

Before you compile PHP4 you need to configure it by running the "./configure" command with the options you want to be included in PHP4.

We use a small shell script called "mkphp4-sapi" to avoid having to re-type all the options each time we compile a new version of PHP. The options we use for a typical development server are (you might want to use other options)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#! /bin/sh
./configure --prefix=/usr/share \
--datadir=/usr/share/php4 \
--with-apxs2=/usr/sbin/apxs2 \
--libdir=/usr/share \
--includedir=/usr/include \
--bindir=/usr/bin \
--with-config-file-path=/etc/php4/apache2 \
--enable-mbstring --enable-mbregex \
--with-mysql  \
--with-gd --enable-gd-imgstrttf --enable-gd-native-ttf \
--with-zlib-dir=/usr/lib \
--with-png-dir=/usr/lib \
--with-jpeg-dir=/usr/lib --with-xpm-dir=/usr/X11R6 \
--with-tiff-dir=/usr/lib --with-ttf-dir=/usr/lib \
--with-freetype-dir=/usr/lib \
--enable-ftp \
--enable-memory-limit --enable-safe-mode \
--bindir=/usr/bin \
--enable-bcmath -enable-calendar \
--enable-ctype --with-ftp \
--enable-magic-quotes \
--enable-inline-optimization \
--with-bz2 \
--with-iconv

However there are one thing You should take notice of. We have specified the config file path (where the php.ini resides) to "/etc/php4/apache2/" as You can probably guess from this naming convention it will make it possible to have different ini files for both PHP4 and PHP5. In fact we have four different ini files according to

  1. "/etc/php4/apache2/php.ini" Used by the apache SAPI module version of PHP4

  2. "/etc/php4/cli/php.ini" Used by the standalone client version of PHP4 (/usr/bin/php4)

  3. "/etc/php5/apache2/php.ini" Used by the apache CGI version of PHP5

  4. "/etc/php5/cli/php.ini" Used by the standalone client version of PHP5 (/usr/bin/php5)

When you run this you might get some errors saying that the configuration file cannot find some library. This is a sign that you might have the library installed but not yet have the "*-devel" RPM version added to your system which is needed since this is where all the usual header files needed for compilation would be.

So for example if you get an error like "Cannot find PNG libraries. Please check your that the corresponding "png-devel" library is installed and if not go back to Yast2 and install the needed "*-devel.rpm" versions of the libraries.

When You have been able to successfully run the ./configuration command it is time to compile. Type "make" as usual but do not type "make install", now wait until the compilation finishes.

Note

If you are on a Pentium4 HT or on a real dual CPU machine you can speed up the compilation by instead giving the "make -j3" command which will start up 3 concurrent compilation processes.

Again; Do not run "make install" since this will try to modify the configuration files in a way that isn't SuSE friendly.

The resulting PHP4 that you have built can be found in ".libs/libphp4.so". Now we only want to copy this file to the location of the other Apache2 modules.

Note

Again, PHP is only guaranteed to work with the non-threaded version of Apache2, which means that you should have installed the "apache2-prefork" MPM and NOT the "apache2-worker" MPM.

If you have correctly installed the prefork MPM several existing modules should now be installed in "/usr/lib/apache2-prefork/".

So the only thing that now remains is to copy ".libs/libphp4.so" to "/usr/apache2-prefork/" in order for Apache to find PHP4 as a module.

J.5.2. Step two; Enable the PHP4 module in the Apache2 configuration

There are three steps to needed to enable PHP4 in Apache.

  1. Add php4 to the APACHE_MODULE string in "/etc/sysconfig/apache2" in order so that the startup script in SuSE will add the appropriate LoadModule statement so that Apache will load PHP4 as a module. In our case our module string will look like

    1
    2
    3
    
    APACHE_MODULES="access actions alias auth auth_dbm autoindex cgi \
    dir env expires include log_config mime negotiation setenvif ssl \
    suexec userdir dav dav_svn php4 "

  2. Telling Apache to run files ending in *.php through the PHP4 module. This is done by specifying the MIME type which the PHP4 module registered itself with. In addition we also tell Apache to search for the appropriate PHP index files in case a directory name is given as the URL. We do this by creating a file "php4.conf" with the following content

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    <IfModule sapi_apache2.c>
       AddType application/x-httpd-php .php3
       AddType application/x-httpd-php .php4
       AddType application/x-httpd-php .php
       AddType application/x-httpd-php-source .php3s
       AddType application/x-httpd-php-source .php4s
       AddType application/x-httpd-php-source .phps
       DirectoryIndex index.php3
       DirectoryIndex index.php4
       DirectoryIndex index.php
    </IfModule>

    and place it in the "/etc/apache2/conf.d/" directory. This will guarantee that it will be read upon startup. The "IfModule" statement in the beginning is just to avoid the statements to be executed in case the PHP4 module is not loaded (we test this by checking if the "sapi_apache2.c" has been activated in Apache).

  3. The final step now is to restart Apache by doing (as root)

    1
    
    $> /etc/init.d/apache2 restart

In order to verify that PHP has been enabled run a standard PHP script; for example by copying the following script to "/srv/www/htdocs/"

1
2
3
<?php 
phpinfo(); 
?>

and name it as "phpinfo.php" . If you now go to your favorite browser and run this script as "http://localhost/phpinfo.php" you should get the standard PHP4 information presented as a quite big table.