How To Use PHP 4.4.9 (FastCGI) With Apache & ISPConfig 3 (Debian Wheezy)

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Follow me on Twitter

Since ISPConfig 3.0.5, it is possible to use multiple PHP versions on one server and select the optimal PHP version for a website. If you have some very old websites on your server, they might not work with PHP5, but only with PHP4. This tutorial shows how to build PHP 4.4.9 as a FastCGI version for use with Apache2 on a Debian Wheezy server. This PHP version can be used together with the default PHP (installed through apt) in ISPConfig.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

PHP-FPM is not available for PHP4, therefore I just describe how to build a FastCGI version of PHP4. FastCGI is available only for Apache servers, therefore you cannot use it with nginx..

 

2 Building PHP 4.4.9 (FastCGI)

Install the prerequisites for building from source code:

apt-get install build-essential

PHP 4.4.9 will not compile with modern OpenSSL versions, therefore we need to install an older OpenSSL version (0.9.8x) first:

cd /tmp
wget http://www.openssl.org/source/openssl-0.9.8x.tar.gz
tar xvfz openssl-0.9.8x.tar.gz
cd openssl-0.9.8x
./config --prefix=/usr/local/openssl-0.9.8
make
make install

Download and extract PHP 4.4.9:

mkdir /opt/phpfcgi-4.4.9
mkdir /usr/local/src/php4-build
cd /usr/local/src/php4-build
wget http://de.php.net/get/php-4.4.9.tar.bz2/from/this/mirror -O php-4.4.9.tar.bz2
tar jxf php-4.4.9.tar.bz2

cd php-4.4.9/

Create some necessary symlinks:

ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/
ln -s /usr/lib/x86_64-linux-gnu/libpng.so /usr/lib/
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 /usr/lib/
ln -s /usr/lib/x86_64-linux-gnu/libexpat.so /usr/lib/
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so /usr/lib/libmysqlclient.so
mkdir /usr/kerberos
ln -s /usr/lib/x86_64-linux-gnu /usr/kerberos/lib

Next we must disable the functions mysql_drop_db and mysql_create_db because otherwise you will get these errors when you try to build PHP 4.4.9:

error: undefined reference to 'mysql_drop_db'
error: undefined reference to 'mysql_create_db'

Open /usr/local/src/php4-build/php-4.4.9/ext/mysql/php_mysql.c...

vi /usr/local/src/php4-build/php-4.4.9/ext/mysql/php_mysql.c

... and go to line 1131. From there on, comment out both functions:

[...]
/*PHP_FUNCTION(mysql_create_db)
{
        zval **db, **mysql_link;
        int id;
        php_mysql_conn *mysql;

        switch(ZEND_NUM_ARGS()) {
                case 1:
                        if (zend_get_parameters_ex(1, &db)==FAILURE) {
                                RETURN_FALSE;
                        }
                        id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
                        CHECK_LINK(id);
                        break;
                case 2:
                        if (zend_get_parameters_ex(2, &db, &mysql_link)==FAILURE) {
                                RETURN_FALSE;
                        }
                        id = -1;
                        break;
                default:
                        WRONG_PARAM_COUNT;
                        break;
        }

        php_error_docref(NULL TSRMLS_CC, E_NOTICE, "This function is deprecated, please use mysql_query() to issue a SQL CREATE DATABASE statement instead.");

        ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, id, "MySQL-Link", le_link, le_plink);

        PHPMY_UNBUFFERED_QUERY_CHECK();

        convert_to_string_ex(db);

        if (mysql_create_db(&mysql->conn, Z_STRVAL_PP(db))==0) {
                RETURN_TRUE;
        } else {
                RETURN_FALSE;
        }
}*/
/* }}} */

/* {{{ proto bool mysql_drop_db(string database_name [, int link_identifier])
   Drops (delete) a MySQL database */
/*PHP_FUNCTION(mysql_drop_db)
{
        zval **db, **mysql_link;
        int id;
        php_mysql_conn *mysql;

        switch(ZEND_NUM_ARGS()) {
                case 1:
                        if (zend_get_parameters_ex(1, &db)==FAILURE) {
                                RETURN_FALSE;
                        }
                        id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
                        CHECK_LINK(id);
                        break;
                case 2:
                        if (zend_get_parameters_ex(2, &db, &mysql_link)==FAILURE) {
                                RETURN_FALSE;
                        }
                        id = -1;
                        break;
                default:
                        WRONG_PARAM_COUNT;
                        break;
        }

        php_error_docref(NULL TSRMLS_CC, E_NOTICE, "This function is deprecated, please use mysql_query() to issue a SQL DROP DATABASE statement instead.");


        ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, id, "MySQL-Link", le_link, le_plink);

        convert_to_string_ex(db);

        if (mysql_drop_db(&mysql->conn, Z_STRVAL_PP(db))==0) {
                RETURN_TRUE;
        } else {
                RETURN_FALSE;
        }
}*/
/* }}} */
[...]

Install the prerequisites for building PHP5 (in our case this also covers the prerequisites for building PHP4):

apt-get build-dep php5

Configure and build PHP 4.4.9 as follows (you can adjust the ./configure command to your needs, take a look at

./configure --help

to see all available options; if you use a different ./configure command, it is possible that additional libraries are required, or the build process will fail):

./configure \
--prefix=/opt/phpfcgi-4.4.9 \
--with-pdo-pgsql \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-soap \
--enable-calendar \
--with-curl \
--with-mcrypt \
--with-zlib \
--with-gd \
--with-pgsql \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-mysql=/usr \
--with-mysql-sock=/var/run/mysqld/mysqld.sock \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--enable-gd-native-ttf \
--with-openssl=/usr/local/openssl-0.9.8 \
--with-openssl-dir=/usr/local/openssl-0.9.8 \
--with-libdir=/lib/x86_64-linux-gnu \
--enable-ftp \
--with-imap \
--with-imap-ssl \
--with-kerberos \
--with-gettext \
--with-expat-dir=/usr \
--enable-fastcgi

The last switch (--enable-fastcgi) makes sure this PHP version will work with FastCGI.

make
make install

Copy php.ini to the correct location:

cp /usr/local/src/php4-build/php-4.4.9/php.ini-recommended /opt/phpfcgi-4.4.9/lib/php.ini

That's it - we will now add the APC module to our PHP 4.4.9 installation:

cd /tmp
wget http://pecl.php.net/get/APC-3.0.19.tgz
tar xvfz APC-3.0.19.tgz
cd APC-3.0.19
/opt/phpfcgi-4.4.9/bin/phpize
./configure --enable-apc --enable-apc-mmap --with-php-config=/opt/phpfcgi-4.4.9/bin/php-config
make
make install

Afterwards, open /opt/phpfcgi-4.4.9/lib/php.ini...

vi /opt/phpfcgi-4.4.9/lib/php.ini

... and set extension_dir = "/opt/phpfcgi-4.4.9/lib/php/extensions/no-debug-non-zts-20020429" and add the line extension=apc.so at the end of the file (you can also configure some additional APC settings):

[...]
extension_dir = "/opt/phpfcgi-4.4.9/lib/php/extensions/no-debug-non-zts-20020429"
[...]
extension=apc.so
apc.enabled=1
apc.shm_segments=1
apc.shm_size=512
apc.ttl=0
apc.user_ttl=600
apc.gc_ttl=600
apc.enable_cli=1
apc.mmap_file_mask=/tmp/apc.XXXXXX
;apc.mmap_file_mask=/dev/zero
;apc.shm_segments = 5

In ISPConfig 3.0.5, you can configure the new PHP version under System > Additional PHP Versions. On the Name tab, you just fill in a name for the PHP version (e.g. PHP 4.4.9) - this PHP version will be listed under this name in the website settings in ISPConfig:

Go to the FastCGI Settings tab (the PHP-FPM Settings tab can be left empty) and fill out the fields as follows:

If everything is working as expected, you can now choose PHP 4.4.9 for a website in ISPConfig. You can check the PHP version of a website by creating a PHP file with the phpinfo(); function in it and calling that file in your browser:

 

 

About The Author

Falko Timme is the owner of nginx WebhostingTimme Hosting (ultra-fast nginx web hosting). He is the lead maintainer of HowtoForge (since 2005) and one of the core developers of ISPConfig (since 2000). He has also contributed to the O'Reilly book "Linux System Administration".

Share this page:

9 Comment(s)

Add comment

Comments

From:

Don't use PHP 4 on a web server accessible to the internet, though.  There have been no security patches released for over 9000 years now, so it will be exploited.

From: Anonymous


hi,

this script does not work for me, stops after /configure command with:

configure: error: libjpeg.(a|so) not found.

when I try to compile the make file: 

/usr/local/src/php4-build/php-4.4.9 # make
make: *** No targets specified and no makefile found.  Stop.

From: Anonymous

Thank you very much.

It works for me fine.

If you have a problem with libjpeg.so, try to find it in your system

# find / -name libjpeg.so

If you use i386 version of your OS, then your path will be /lib/i386-linux-gnu

 

 

 

From: Arie

Good morning, 

 Do you have a kind of uninstall? Right now the shell defaults to 4.4.9 instead of 5.4. 

 Within ispconfig this is not a problem, but when using phpmyadmin I can't change the upload_max settings.. 

From: Nadir

  worked on wheezy.

 I had to install this:

  apt-get install libjpeg8-dev
 apt-get install libpng12-dev
 apt-get install freetype2
 apt-get install libfreetype6-dev
 apt-get install libmcrypt-dev
  apt-get install  libmysqlclient-dev
  apt-get install  libexpat-dev

then my configure command was:
 
 ./configure --prefix=/opt/phpfcgi-4.4.9 --with-pdo-pgsql --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-soap --enable-calendar --with-mcrypt --with-zlib --with-gd --disable-rpath --enable-inline-optimization --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-mysql=/usr --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-openssl=/usr/local/openssl-0.9.8 --with-openssl-dir=/usr/local/openssl-0.9.8 --with-libdir=/lib/x86_64-linux-gnu --enable-ftp --with-kerberos --with-gettext --with-expat-dir=/usr --enable-fastcgi 
 
 
 

From: Nadir


Addition for the APC part:

 if the phpize command fails, you should add this:

 apt-get install autoconf

 this is required by phpize.

 

From: lonix

I use - 32bit debian 7 (3.2.0-4-686-pae #1 SMP Debian 3.2.65-1+deb7u1 i686 GNU/Linux)

Unfortunately I get for "./configure \ ..." getting this message:configure: error: Kerberos libraries not found.             Check the path given to --with-kerberos (if no path is given, searches in /usr/kerberos, /usr/local and /usr ) All paths are correct, soft links set in all possible directions.the installation of php 5.3 went well. About a tip I can still check I am grateful.

From: Seb

Thank you for this guideline.

By the way, you should never set ttl=0 for APC. It makes it useless.

http://stackoverflow.com/questions/3723316/what-is-causing-unable-to-allocate-memory-for-pool-in-php/12146046#12146046

From: T.J. Janssen

A very nice step-by-step tutorial for newbies. Thank you. How do the "AddHandler" and "Action" statemets have to look in this scenario? Thanks in advance T.J.