Sniptools » Tips/Tricks

Installing PHP5 and PHP4 together on Unix

June 1, 2005 Views (76,838) /  Comments (11) /  Trackback (0) / Digg/Share


So you have PHP4 working on your server, and have heard that PHP5 may break things. Here’s how to have both running alongside.

UPDATE: For the most recent version of this code, you may want to look at Jacob Mather’s original instructions 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 configure | 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 permissions of course, save the code as a file (e.g., “php5install.sh”, CHMOD this file to 644 so it’s executable, and then run it at the command line. If you don’t know any of these things, you shouldn’t be executing this code at all.

Anyway, this should set up PHP5 without interfering without your current setup. The file extension *.php5 will be associated with PHP5.

When the script is done, simply restart Apache. On Linux type setups, it’s as simple as “service httpd restart”. Here’s a good place to begin in terms of new stuff in PHP5

.

Hope this helps!

(282 Words | )

 
Possibly Related
Other stuff that may be of interest  
Comments
What readers have asked/said/added.

^1 Merci said on July 9, 2005 2:04 AM:

thank you for great instructions nut now if I create php file it shows me many errors with functions like file_get_contents, please help!

^2 Shashank said on July 9, 2005 2:09 AM:

Hi, are you saving the new files with a *.php5 extension? If you still save it as *.php then you’re invoking PHP 4.xx and there are several functions that’re only supported in PHP 5. I think file_get_contents() is one of them.

^3 Merci said on July 24, 2005 11:44 AM:

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

^4 Iain Shortreed said on October 10, 2005 10:38 AM:

I tried to run this on a cPanel server with CentOS 3.4 however had many problems. Tried editting it up but still had many problems and it wouldn’t install. Do you offer any support on this?

^5 Shashank Tripathi said on October 26, 2005 5:18 PM:

Ian, what errors? I have installed both versions of php on centos, freebsd, and suse before, no problems.

^6 ISProHosting.com said on November 9, 2005 7:31 AM:

To “Iain Shortreed”: we have compiled the PHP5 along PHP4 on numerous Linux systems and they works OK. We did installed it on CentOS 4 as well. We do use our own script with several more tricks and own configure line and are ready to install PHP5 with any version of PHP4 (cgi or mod_php) for a little fee. Contact me for more details.

^7 petert said on November 25, 2005 9:26 PM:

This is all about the gci version of php. No use at all for people who use php as a module in Apache

^8 Shashank Tripathi said on November 26, 2005 6:02 PM:

petert, this is a template that works. An admin who knows enough to want to install php as a module should know how to tweak the above template to his wishes.

^9 J.F.Kishor said on December 12, 2005 8:25 PM:

SUB : Installing PHP5 and PHP4 together on Unix
Hi,
Thanks for the script. I downloaded the latest, I executed the script installation success. Now PHP4 is working fine and when I execute php scripts with .php5 extension I get the following error message. 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.
Nilgiri Networks,
ooty.


^10 Anthony Ryan said on January 18, 2006 4:56 AM:

Is it possible to disable the xml support when installing php5 with this script?

My problem is my server is on RedHat 7.3, and it cannot install libxml2-2.5.10 because there is no supported glibc_2.3 package.

I don’t really need xml support, so if it could be disabled somehow, I think it would work.

Thanks

^11 Joe said on July 7, 2007 2:12 PM:

Hello,
I have upgraded php to php5 manually but when I browse phpinfo() it still shows php4.4
while php -v shows 5.2.3
any suggestion ?

Thanks

 

Post a comment
Please be decent while posting comments, don't make us delete them, thanks.




Will be spam-protected.

Remember?


Comment Preview

XX said on :

 

Trackbacks
Ping @ /ping/2005-06/137. Listed below are links to weblogs that reference this article.

 

Referrals
*Some* places that viewers have come to this page from: