SniptoolsSniptools | Design & Technology Observations

RSS

Installing PHP5 and PHP4 together on Unix

Jun 1st 2005
11 Comments

Respond
Trackback

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

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!




This post is tagged

11 Comments

  1. Merci

    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. 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

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

  4. Iain Shortreed

    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. Ian, what errors? I have installed both versions of php on centos, freebsd, and suse before, no problems.

  6. 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

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

  8. 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

    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

    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

    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

Incoming Links