Search This Blog

Sunday, January 01, 2006

Install PHP5 to be run in parallel with PHP4 in same apache web server instance.

I had PHP4 already installed as module. I wanted the XML functions included in PHP5. The scripts had previously been written in PHP4 and I didnt want to take the pain of changing the scripts. So searched for a way to install PHP5 to be run in parallel with PHP4 on the same Apache web server.
I use Apache 2.0.52 on Fedora core 3. So cant guarantee that this would be helpful to you.

I have installed PHP4 as module and PHP5 as cgi.

Create a cgi-sys folder in /usr/local.

Save the following script as a sh file and run it as root.
Dont forget to check the version of PHP5 you wish to install , the location of PHP currently installed and the location of conf directory for apache.


cd /usr/src
wget -O php.tbz2 "${VERSION}.tar.bz2/from/this/mirror"
tar -xjvf php.tbz2
rm -f php.tbz2

cd php-${VERSION}


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 --enable-force-cgi-redirect --enable-discard-path"

./configure $CFGLINE

make install

if [ -f /usr/local/php5/bin/php ]
# cp -f php.ini-recommended /usr/local/php5/lib/php.ini

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

echo "ScriptAlias /cgi-sys \"/usr/local/cgi-sys/php5\"" > $HTTPD_CONF_DIR/php5.conf
echo "Action application/x-httpd-php5 \"/cgi-sys/php5\"" > $HTTPD_CONF_DIR/php5.conf
echo "AddType application/x-httpd-php5 .php5" >> $HTTPD_CONF_DIR/php5.conf

TEST=`grep php5.conf $HTTPD_CONF_DIR/httpd.conf`

if [ "$TEST" = "" ]
echo "Include ${HTTPD_CONF_DIR}/php5.conf" >> $HTTPD_CONF_DIR/httpd.conf
/etc/init.d/httpd restart
echo "There was an error..."

No comments: