As we all know php4 will no longer be maintained. Why should it? PHP5 has been out for how long now?
In my setup, I have the latest php5 rpms installed on my box replacing php4 some years back. I will be going over how to add php4 by building from source with existing php5 installed via RPMs.
Things to consider before doing this how to, I post this as a guide to help lead someone in the right direction. What I put here has worked for me with one test box using Ensim 4 and my other Ensim Pro X production boxes. Following this how to means you do it at your own risk. I assume no responsibility for anyone who kills their box by following this (even though I don’t think it’s possible but you never know). Also keep in mind we are building php4 from source and it will run in CGI mode, not SAPI. This could open security risks. DO NOT setup SUPHP to run as root by any means! Read about suphp at their website to get a better understanding of how it works.
Anyways, let get down to business.
Change over to the /usr/local/src directory and download the latest php 4 and my patched version suphp. I am not the owner/creator of suphp, just made a couple of changes to the mod_suphp.c to allow this to work correctly.
Download the latest php from http://php.net.
Download suphp here: http://www.amsdi.com/downloads/linux/src/s....patched.tar.gz
Untar both archives:
CODE
# tar zxvf suphp-0.6.2.patched.tar.gz
# tar zxvf php-4.4.8.tar.gz
# tar zxvf php-4.4.8.tar.gz
When I tried to build php4, i had build issues with imap enabled. To fix, download libc-client-devel. On my box I have multiple versions of libc-client and the devel would not install via up2date with the latest version from redhat. The build worked fine on my CentOS box without having to do this but not saying this will be your case. This is mainly directed toward RHEL users. This may work with CentOS but has not tested. When I ran rpm -qa |grep ^libc-client i saw version 2002e-14 with no devel and a newer version of the package. This is what I did to get the RPM on redhat.
CODE
up2date --download libc-client-devel
rpm -ivh /var/spool/up2date/libc-client-devel-2002e-14.i386.rpm
rpm -ivh /var/spool/up2date/libc-client-devel-2002e-14.i386.rpm
Time to build PHP:
cd ./php-4.4.8
Run this configure line, change up to suit your needs:
CODE
./configure --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu \
--target=i386-redhat-linux-gnu --prefix=/usr/local/php4 \
--cache-file=../config.cache --with-config-file-path=/usr/local/php4/etc/php.ini \
--enable-force-cgi-redirect --disable-debug --enable-pic \
--disable-rpath --enable-inline-optimization --with-bz2 \
--with-db4=/usr --with-curl --with-freetype-dir=/usr \
--with-png-dir=/usr --with-gd --enable-gd-native-ttf \
--without-gdbm --with-gettext --with-ncurses --with-gmp \
--with-iconv --with-jpeg-dir=/usr --with-ssl --with-png \
--with-regex=system --with-xml --with-expat-dir=/usr \
--with-dom=shared,/usr --with-dom-xslt=/usr \
--with-dom-exslt=/usr --with-xmlrpc=shared \
--with-pcre-regex=/usr --with-zlib --enable-bcmath --enable-exif \
--enable-ftp --enable-magic-quotes --enable-sockets \
--enable-sysvsem --enable-sysvshm --enable-discard-path \
--enable-track-vars --enable-trans-sid --enable-yp --enable-wddx --enable-soap \
--with-snmp=shared --without-oci8 --with-mysqli=/usr/bin/mysql_config --with-ldap \
--with-mysql --with-pgsql --with-imap --with-imap-ssl --with-kerberos --enable-mysqli \
--enable-memory-limit --enable-bcmath --enable-shmop --enable-mysql \
--enable-pgsql --enable-imap --enable-calendar --enable-dbx --enable-dio --enable-mcal \
--enable-mbstring=shared --enable-mbstr-enc-trans --without-unixODBC \
--without-odbc --enable-mbregex --with-pic --enable-force-cgi-redirect \
--enable-fastcgi
--target=i386-redhat-linux-gnu --prefix=/usr/local/php4 \
--cache-file=../config.cache --with-config-file-path=/usr/local/php4/etc/php.ini \
--enable-force-cgi-redirect --disable-debug --enable-pic \
--disable-rpath --enable-inline-optimization --with-bz2 \
--with-db4=/usr --with-curl --with-freetype-dir=/usr \
--with-png-dir=/usr --with-gd --enable-gd-native-ttf \
--without-gdbm --with-gettext --with-ncurses --with-gmp \
--with-iconv --with-jpeg-dir=/usr --with-ssl --with-png \
--with-regex=system --with-xml --with-expat-dir=/usr \
--with-dom=shared,/usr --with-dom-xslt=/usr \
--with-dom-exslt=/usr --with-xmlrpc=shared \
--with-pcre-regex=/usr --with-zlib --enable-bcmath --enable-exif \
--enable-ftp --enable-magic-quotes --enable-sockets \
--enable-sysvsem --enable-sysvshm --enable-discard-path \
--enable-track-vars --enable-trans-sid --enable-yp --enable-wddx --enable-soap \
--with-snmp=shared --without-oci8 --with-mysqli=/usr/bin/mysql_config --with-ldap \
--with-mysql --with-pgsql --with-imap --with-imap-ssl --with-kerberos --enable-mysqli \
--enable-memory-limit --enable-bcmath --enable-shmop --enable-mysql \
--enable-pgsql --enable-imap --enable-calendar --enable-dbx --enable-dio --enable-mcal \
--enable-mbstring=shared --enable-mbstr-enc-trans --without-unixODBC \
--without-odbc --enable-mbregex --with-pic --enable-force-cgi-redirect \
--enable-fastcgi
If that finsihes with no error, run:
CODE
make
If PHP builds with no errors, go ahead and install
CODE
make install
That will put all the files in the /usr/local/php4 folder.
Run this command to symlink the php4 binary in the /usr/bin directory for cli users:
CODE
ln -s /usr/local/php4/bin/php /usr/bin/php4
Test:
CODE
# php4 -v
PHP 4.4.8 (cgi-fcgi) (built: Feb 19 2008 18:02:54)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
PHP 4.4.8 (cgi-fcgi) (built: Feb 19 2008 18:02:54)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
Congrats, if that works you now have php4 built on your OS! Run php -v to make sure php5 still working correctly.
Now, lets build the mod_suphp apache module.
cd /usr/local/src/suphp-0.6.2
CODE
./configure --with-min-uid=100 --with-min-gid=100 --with-apache-user=apache \
--with-php=/usr/local/php4/bin/php --with-logfile=/var/log/httpd/suphp_log \
--with-apxs=/usr/sbin/apxs
make
make install
--with-php=/usr/local/php4/bin/php --with-logfile=/var/log/httpd/suphp_log \
--with-apxs=/usr/sbin/apxs
make
make install
After you compile suphp, replace the contents of /usr/local/etc/suphp.conf file with this:
CODE
[global]
;Path to logfile
logfile=/var/log/suphp.log
;Loglevel
loglevel=info
;User Apache is running as
webserver_user=apache
;Path all scripts have to be in
docroot=/
;Path to chroot() to before executing script
;chroot=/mychroot
; Security options
allow_file_group_writeable=false
allow_file_others_writeable=false
allow_directory_group_writeable=false
allow_directory_others_writeable=false
;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=true
;Send minor error messages to browser
errors_to_browser=true
;PATH environment variable
env_path=/bin:/usr/bin
;Umask to set, specify in octal notation
umask=0077
; Minimum UID
min_uid=100
; Minimum GID
min_gid=100
[handlers]
;Handler for php-scripts
x-httpd-php4=php:/usr/local/php4/bin/php
;Handler for CGI-scripts
x-suphp-cgi=execute:!self
;Path to logfile
logfile=/var/log/suphp.log
;Loglevel
loglevel=info
;User Apache is running as
webserver_user=apache
;Path all scripts have to be in
docroot=/
;Path to chroot() to before executing script
;chroot=/mychroot
; Security options
allow_file_group_writeable=false
allow_file_others_writeable=false
allow_directory_group_writeable=false
allow_directory_others_writeable=false
;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=true
;Send minor error messages to browser
errors_to_browser=true
;PATH environment variable
env_path=/bin:/usr/bin
;Umask to set, specify in octal notation
umask=0077
; Minimum UID
min_uid=100
; Minimum GID
min_gid=100
[handlers]
;Handler for php-scripts
x-httpd-php4=php:/usr/local/php4/bin/php
;Handler for CGI-scripts
x-suphp-cgi=execute:!self
Now edit the /etc/httpd/conf/httpd.conf file, add the following after LoadModule fastcgi_module modules/mod_fastcgi.so:
CODE
LoadModule suphp_module /usr/lib/httpd/modules/mod_suphp.so
Any thats it! Restart apache.
CODE
/etc/rc.d/init.d/httpd restart
Now you have to add php4 support to any domains of your choosing. All you have to do is create a file called php4 in the /etc/httpd/conf/siteXX directory (replace XX with site id) for each domain you want to run php4 with php5 with the following:
CODE
suPHP_Engine on
suPHP_UserGroup adminXX adminXX
AddHandler x-httpd-php4 .php4
suPHP_AddHandler x-httpd-php4
suPHP_UserGroup adminXX adminXX
AddHandler x-httpd-php4 .php4
suPHP_AddHandler x-httpd-php4
If you want to add it to all your domains that have apache enabled, create a shell script with the following and run it then restart apache:
CODE
#/bin/sh
SITES=`/usr/local/bin/sitelookup -a site_handle`
for SITE_HANDLE in $SITES
do
ADMIN=`echo $SITE_HANDLE | sed s/site/admin/g`
ENABLED=`less /home/virtual/$SITE_HANDLE/info/current/apache |grep enabled| tr -d 'enabled = '`
# Is apache enabled for this site?
if [ "$ENABLED" -eq "1" ]; then
cat <<EOF >> /etc/httpd/conf/$SITE_HANDLE/php4
suPHP_Engine on
suPHP_UserGroup $ADMIN $ADMIN
AddHandler x-httpd-php4 .php4
suPHP_AddHandler x-httpd-php4
EOF
echo Updated $SITE_HANDLE
else
echo Skipping $SITE_HANDLE
fi
done
SITES=`/usr/local/bin/sitelookup -a site_handle`
for SITE_HANDLE in $SITES
do
ADMIN=`echo $SITE_HANDLE | sed s/site/admin/g`
ENABLED=`less /home/virtual/$SITE_HANDLE/info/current/apache |grep enabled| tr -d 'enabled = '`
# Is apache enabled for this site?
if [ "$ENABLED" -eq "1" ]; then
cat <<EOF >> /etc/httpd/conf/$SITE_HANDLE/php4
suPHP_Engine on
suPHP_UserGroup $ADMIN $ADMIN
AddHandler x-httpd-php4 .php4
suPHP_AddHandler x-httpd-php4
EOF
echo Updated $SITE_HANDLE
else
echo Skipping $SITE_HANDLE
fi
done
If you want any new domains to have php4 enabled, edit or create the /etc/appliance/customization/virtDomain.sh
CODE
DOMAIN=$1
SITE_HANDLE=`/usr/local/bin/sitelookup -d $DOMAIN site_handle`
/etc/appliance/customization/php4.sh $SITE_HANDLE
SITE_HANDLE=`/usr/local/bin/sitelookup -d $DOMAIN site_handle`
/etc/appliance/customization/php4.sh $SITE_HANDLE
And create /etc/appliance/customization/php4.sh with the following:
CODE
#!/bin/sh
SITE=$1
ADMIN=`echo $SITE | sed s/site/admin/g`
ENABLED=`less /home/virtual/$SITE/info/current/apache |grep enabled| tr -d 'enabled = '`
# Is apache enabled for this site?
if [ "$ENABLED" -eq "1" ]; then
cat <<EOF >> /etc/httpd/conf/$SITE/php4
suPHP_Engine on
suPHP_UserGroup $ADMIN $ADMIN
AddHandler x-httpd-php4 .php4
suPHP_AddHandler x-httpd-php4
EOF
fi
SITE=$1
ADMIN=`echo $SITE | sed s/site/admin/g`
ENABLED=`less /home/virtual/$SITE/info/current/apache |grep enabled| tr -d 'enabled = '`
# Is apache enabled for this site?
if [ "$ENABLED" -eq "1" ]; then
cat <<EOF >> /etc/httpd/conf/$SITE/php4
suPHP_Engine on
suPHP_UserGroup $ADMIN $ADMIN
AddHandler x-httpd-php4 .php4
suPHP_AddHandler x-httpd-php4
EOF
fi
And you're done!
You should now be able to run php and php4 side by side under apache.
Note: php4 files must only be writable by owner, not group or world (chmod 644) and must belong to the site admin. If the file is not owned by the admin and is writable to other users, you will get a 500 error.