Help - Search - Members - Calendar
Full Version: How to: PHP5 and PHP4 under apache
The Planet Forums > Control Panels > Ensim > Ensim HOWTOs
AdamS
I noticed there are still many people looking to have both php4 and php5 support on their ensim box. I figured I would contribute to the community since I have done this and it works flawlessly. I have clients that have older poorly written scripts that just would not work on php 5. Instead of editing all the files for them (which I don't have time to do) since the author for some reason decides not to maintain their script anymore, makes it a lot easier on me. This will be extremely helpful to those who upgrade to php6 in the future when it’s time to upgrade.

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


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


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


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


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


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


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



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



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


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


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.
markcausa
Great! Thank you for adding this tutorial. smile.gif
Netino
A minor correction?

in the last script, in the fifth line, where:

CODE
ENABLED=`less /home/virtual/site12/info/current/apache |grep enabled| tr -d 'enabled = '`


wouldn´t:

CODE
ENABLED=`less /home/virtual/$SITE/info/current/apache |grep enabled| tr -d 'enabled = '`


Regards,
Netino
markcausa
Ah, good catch!
AdamS
Yes, good catch. Fixed first post. Thanks for bringing that to my attention!
nspirov
Excellent HOWTO, thank you so much!

I have one problem, though:
In PHP4 I can't change configuration options, its config file should be
/usr/local/php4/etc/php.ini
and phpinfo() shows exactly the same, BUT:

1. This file /usr/local/php4/etc/php.ini was not present after installation;
2. When I created it, it doesn't work (settings in this file are not reflected in PHP4s phpinfo() )
Of course I restarted httpd and everything.

Am I missing something?

Thank you for your help!
nspirov
I found the answer to my question, you have an error in the compile options in your HOWTO:

QUOTE (PHP Manual)
--with-config-file-path=PATH
Sets the path in which to look for php.ini, defaults to PREFIX/lib.


So it should be --with-config-file-path=/usr/local/php4/etc

Since I'm lazy I still haven't recompiled it, but setting this option in the Apache PHP config does the job fixing it:

suPHP_ConfigPath /usr/local/php4/etc

Let's hope somebody still reads this forum so this can be helpful
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.