Installing PHP5 and PHP4 together on Unix

Written by Shanx June 1st, 2005

installing php5 without breaking php4

Continue reading →
Close

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!

Posted in Miscellaneous

11 Comments

Tagged with

11 Comments

  1. Merci says:

    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. sniptools says:

    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 says:

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

  4. Iain Shortreed says:

    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. sniptools says:

    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 says:

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

  8. sniptools says:

    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 says:

    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 says:

    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 says:

    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

Leave a Reply

Miscellaneous

I use the Nokia e61i as my mobile. Instead of my telco’s data plan (which offers me a meagre 1GB per month) I simply prefer to use my home wireless [...]

Continue reading →

View all

Web Tools

If you use Firefox (and if not, what are you waiting for?) you are familiar with useful extensions such as Video Downloader, which allow you to save local copies of [...]

Continue reading →

View all

Databases

This regexp worked for me. SELECT * FROM table WHERE NOT column ~ ( ‘^(‘|| $$[\09\0A\0D\x20-\x7E]|$$|| — ASCII $$[\xC2-\xDF][\x80-\xBF]|$$|| — non-overlong 2-byte $$\xE0[\xA0-\xBF][\x80-\xBF]|$$|| — excluding overlongs $$[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|$$|| — straight 3-byte [...]

Continue reading →

View all

Windows

So you’ve been visited by the much dreaded CRC — Cyclical Redundancy Check error, most likely encountered while copying files between hard disks. On Mac OSX, this will usually appear [...]

Continue reading →

View all

Mac OSX

A simple app ought to do it. Download iRinger. It’s a Windows app. If you’re on Mac, you’ll want to use it within a virtual machine, like Parallels or VMWare [...]

Continue reading →

View all

System Maintenance

I use the Nokia e61i as my mobile. Instead of my telco’s data plan (which offers me a meagre 1GB per month) I simply prefer to use my home wireless [...]

Continue reading →

View all

Wordpress

Among many new exciting features, WordPress 2.6 released the ability to store each and every revision of your posts, like an elaborate update history. Now this can be a pretty [...]

Continue reading →

View all

Audio/Video

Panic, the makers of some fantastic software such as Transmit or Panic, also have the most light-weight audio converter for the Mac OSX platform. It’s called Audion: get it here. [...]

Continue reading →

View all

iPhone

A simple app ought to do it. Download iRinger. It’s a Windows app. If you’re on Mac, you’ll want to use it within a virtual machine, like Parallels or VMWare [...]

Continue reading →

View all