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

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Tue, 2013-06-18 17:33. :: Debian | ISPConfig | Web Server | Apache | Control Panels | PHP

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
Last edited 06/18/2013

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:

Click to enlarge

 

3 Links

 

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".


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Arie (not registered) on Fri, 2014-02-07 08:05.

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.. 

Submitted by Anonymous (not registered) on Sat, 2013-12-14 11:54.
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

 

 

 

Submitted by Anonymous (not registered) on Mon, 2013-11-18 04:27.

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.

Submitted by ofus (registered user) on Wed, 2013-09-11 11:27.

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.