Installing PHP5 and PHP4 together on Unix

So you have PHP4 work­ing on your server, and have heard that PHP5 may break things. Here's how to have both run­ning alongside.

So you have PHP4 work­ing on your server, and have heard that PHP5 may break things. Here's how to have both run­ning alongside.

UPDATE: For the most recent ver­sion of this code, you may want to look at Jacob Mather's orig­i­nal instruc­tions on his WebOnce site.
#!/bin/sh
# PHP5 CGI Installer for cPanel/WHM Servers

VERSION=5.0.4
cd /usr/src
wget –O php.tbz2 "http://us4.php.net/get/php-${VERSION}.tar.bz2/from/this/mirror"
tar –xjvf php.tbz2
rm –f php.tbz2
wget http://choon.net/opensource/php/php-${VERSION}-mail-header.patch
cd php-${VERSION}
patch –p1 < /usr/src/php-${VERSION}-mail-header.patch
rm /usr/src/php-${VERSION}-mail-header.patch

PHP=/usr/local/bin/php
CFG=`$PHP –i | grep con­fig­ure | sed "s/'//g" | sed "s/./configure (.*) – with-apxs.*apxs (.*)/1 2/"`
CFGLINE="${CFG##* => } –prefix=/usr/local/php5 –exec-prefix=/usr/local/php5 –program-suffix=5 –enable-force-cgi-redirect –enable-discard-path"

./configure $CFGLINE
make
make install

cp –f php.ini-recommended /usr/local/php5/lib/php.ini

cp /usr/local/php5/bin/php5 /usr/local/cpanel/cgi-sys/php5
chown root:wheel /usr/local/cpanel/cgi-sys/php5

echo "Action application/x-httpd-php5 "/cgi-sys/php5"" > /usr/local/apache/conf/php5.conf
echo "AddType application/x-httpd-php5 .php5" >> /usr/local/apache/conf/php5.conf

TEST=`grep php5.conf /usr/local/apache/conf/httpd.conf`

if [ "$TEST" = "" ]
then
echo "Include /usr/local/apache/conf/php5.conf" >> /usr/local/apache/conf/httpd.conf
echo "Your all set to restart your apache now. "
fi

You'll need to run this code with root per­mis­sions of course, save the code as a file (e.g., "php5install.sh", CHMOD this file to 644 so it's exe­cutable, and then run it at the com­mand line. If you don't know any of these things, you shouldn't be exe­cut­ing this code at all.

Any­way, this should set up PHP5 with­out inter­fer­ing with­out your cur­rent setup. The file exten­sion *.php5 will be asso­ci­ated with PHP5.

When the script is done, sim­ply restart Apache. On Linux type setups, it's as sim­ple as "ser­vice httpd restart". Here's a good place to begin in terms of new stuff in PHP5

.

Hope this helps!

11 comments
  1. Merci says: Jul 09, 20052:04 am

    thank you for great instruc­tions nut now if I cre­ate php file it shows me many errors with func­tions like file_get_contents, please help!

  2. sniptools says: Jul 09, 20052:09 am

    Hi, are you sav­ing the new files with a *.php5 exten­sion? If you still save it as *.php then you're invok­ing PHP 4.xx and there are sev­eral func­tions that're only sup­ported in PHP 5. I think file_get_contents() is one of them.

  3. Merci says: Jul 24, 200511:44 am

    thank you shashank yes that worked silly me, do you know a way to have php5 work­ing with mysql 5 beta?

  4. Iain Shortreed says: Oct 10, 200510:38 am

    I tried to run this on a cPanel server with Cen­tOS 3.4 how­ever had many prob­lems. Tried edit­ting it up but still had many prob­lems and it wouldn't install. Do you offer any sup­port on this?

  5. sniptools says: Oct 26, 20055:18 pm

    Ian, what errors? I have installed both ver­sions of php on cen­tos, freebsd, and suse before, no problems.

  6. ISProHosting.com says: Nov 09, 20057:31 am

    To "Iain Short­reed": we have com­piled the PHP5 along PHP4 on numer­ous Linux sys­tems and they works OK. We did installed it on Cen­tOS 4 as well. We do use our own script with sev­eral more tricks and own con­fig­ure line and are ready to install PHP5 with any ver­sion of PHP4 (cgi or mod_php) for a lit­tle fee. Con­tact me for more details.

  7. petert says: Nov 25, 20059:26 pm

    This is all about the gci ver­sion of php. No use at all for peo­ple who use php as a mod­ule in Apache

  8. sniptools says: Nov 26, 20056:02 pm

    petert, this is a tem­plate that works. An admin who knows enough to want to install php as a mod­ule should know how to tweak the above tem­plate to his wishes.

  9. J.F.Kishor says: Dec 12, 20058:25 pm

    SUB : Installing PHP5 and PHP4 together on Unix
    Hi,
    Thanks for the script. I down­loaded the lat­est, I exe­cuted the script instal­la­tion suc­cess. Now PHP4 is work­ing fine and when I exe­cute php scripts with .php5 exten­sion I get the fol­low­ing error mes­sage. Can you please help on this ?

    Not Found
    The requested URL /cgi-sys/php5/~kishor/phpFiles/phpinfo.php5 was not found on this server.

    Thanks in advance

    Regards,
     – J F K
    J.F.Kishor.
    Nil­giri Net­works,
    ooty.

  10. Anthony Ryan says: Jan 18, 20064:56 am

    Is it pos­si­ble to dis­able the xml sup­port when installing php5 with this script?

    My prob­lem is my server is on Red­Hat 7.3, and it can­not install libxml2-2.5.10 because there is no sup­ported glibc_2.3 package.

    I don't really need xml sup­port, so if it could be dis­abled some­how, I think it would work.

    Thanks

  11. Joe says: Jul 07, 20072:12 pm

    Hello,
    I have upgraded php to php5 man­u­ally but when I browse phpinfo() it still shows php4.4
    while php –v shows 5.2.3
    any suggestion ?

    Thanks

Submit comment