and at the same time?

I tried running both and modules at the same time by putting this in my /etc/httpd/conf.d/php.conf file:

LoadModule php5_module modules/
LoadModule php4_module modules/

AddHandler php5-script .php
AddHandler php-script .php4
AddType text/html .php
AddType text/html .php4

Doesn’t work… apache will restart, but any pages I hit seg fault now. Ug, oh well, it was worth a shot. My collegue told me he read it wasn’t possible, and I’ve seen some forum posts to support this, but I wanted to be sure. Unless there is a magic trick, cannot do it as apache modules.


What you can do, though, is run one of them as CGI. Since I am already running PHP5 as an apache module, I’ll leave that alone and build a PHP4 CGI binary, from source. You may want to consider which one you run as a module and which as CGI, because CGI is slower.

Ok, so on with the example. I used the same configure line that my php5 was built with, just removed the ‘–with-apxs2=/usr/sbin/apxs’ and changed to ‘–with-config-file-path=/etc/php4′ ‘–with-config-file-scan-dir=/etc/php4/php.d’ so I can have a different php.ini file for php4.

cd /usr/local/src
wget wget
tar -xzvf php-4.4.4.tar.gz
cd php-4.4.4
‘./configure’ ‘–build=i386-redhat-linux’ ‘–host=i386-redhat-linux’ ‘–target=i386-redhat-linux-gnu’ ‘–program-prefix=’ ‘–prefix=/usr’ ‘–exec-prefix=/usr’ ‘–bindir=/usr/bin’ ‘–sbindir=/usr/sbin’ ‘–sysconfdir=/etc’ ‘–datadir=/usr/share’ ‘–includedir=/usr/include’ ‘–libdir=/usr/lib’ ‘–libexecdir=/usr/libexec’ ‘–localstatedir=/var’ ‘–sharedstatedir=/usr/com’ ‘–mandir=/usr/share/man’ ‘–infodir=/usr/share/info’ ‘–cache-file=../config.cache’ ‘–with-libdir=lib’ ‘–with-config-file-path=/etc/php4′ ‘–with-config-file-scan-dir=/etc/php4/php.d’ ‘–disable-debug’ ‘–with-pic’ ‘–disable-rpath’ ‘–with-bz2′ ‘–with-curl’ ‘–with-exec-dir=/usr/bin’ ‘–with-freetype-dir=/usr’ ‘–with-png-dir=/usr’ ‘–enable-gd-native-ttf’ ‘–without-gdbm’ ‘–with-gettext’ ‘–with-gmp’ ‘–with-iconv’ ‘–with-jpeg-dir=/usr’ ‘–with-openssl’ ‘–with-png’ ‘–with-pspell’ ‘–with-expat-dir=/usr’ ‘–with-pcre-regex=/usr’ ‘–with-zlib’ ‘–with-layout=GNU’ ‘–enable-exif’ ‘–enable-ftp’ ‘–enable-magic-quotes’ ‘–enable-sockets’ ‘–enable-sysvsem’ ‘–enable-sysvshm’ ‘–enable-sysvmsg’ ‘–enable-track-vars’ ‘–enable-trans-sid’ ‘–enable-yp’ ‘–enable-wddx’ ‘–with-pear=/usr/share/pear’ ‘–with-kerberos’ ‘–enable-ucd-snmp-hack’ ‘–with-unixODBC=shared,/usr’ ‘–enable-memory-limit’ ‘–enable-shmop’ ‘–enable-calendar’ ‘–enable-dbx’ ‘–enable-dio’ ‘–with-mime-magic=/etc/httpd/conf/magic’ ‘–without-sqlite’ ‘–with-libxml-dir=/usr’ ‘–with-xml’ ‘–with-mysql=/usr/local/mysql’ ‘–without-gd’ ‘–without-odbc’ ‘–disable-dom’ ‘–disable-dba’
# change this to goto your cgi-bin:
cp sapi/cgi/php /var/www/vhosts/
# If you are using suexec_module/SuexecUserGroup for your VirtualHost,
# then you’ll need to chown the newly created cgi file to the correct user:
chown dave:psacln /var/www/vhosts/
# put the default php.ini file in place, I may want to edit it later:
mkdir /etc/php4
cp php.ini-recommended /etc/php4/php.ini

So, what I have done is created a new cgi version of php4 and dropped it in my cgi-bin dir, and CHANGED THE OWNERSHIP (this took me awhile to figure out, if it’s root owned, you cannot execute it through suexec_module).

Now configure your site to use it. The best way is to drop a .htaccess file in folders where you want to run php4:


Action php4-cgi /cgi-bin/php4
AddHandler php4-cgi .php

Comments are closed.