PDA

View Full Version : PHP 5 alongside PHP 4 for cPanel


elix
10-02-2006, 09:42 AM
/scripts/checkccompiler

rm -rf /home/cpphpbuild
mkdir /home/cpphpbuild
cd /home/cpphpbuild

wget http://us2.php.net/get/php-5.2.3.tar.gz/from/this/mirror
tar zfx php-5.2.3.tar.gz
cd php-5.2.3

echo "#define HAVE_SENDMAIL 1" >> /home/cpphpbuild/php-5.2.3/main/php_config.h

wget http://www.elix.us/tutorials/php5.gen.cpanel
chmod 700 php5.gen.cpanel
./php5.gen.cpanel #and follow instructions


make
make install

# if anything fails DO NOT move on.

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

cp -p /home/cpphpbuild/php-5.2.3/php.ini-recommended /usr/local/php5/lib/php.ini
chown root.root /usr/local/php5/lib/php.ini
chmod 644 /usr/local/php5/lib/php.ini

echo "cgi.fix_pathinfo = 1 ; needed for CGI/FastCGI mode" >> /usr/local/php5/lib/php.ini

#------------------------------------------#

"Now we need to add several lines to Apache.

Run editor (you may use "vi" or "pico -w"):
pico -w /usr/local/apache/conf/httpd.conf

Scroll down (better use the built-in search) to the "<IfModule mod_dir.c>"
There we should to add index.php5 after index.jp, but before index.php4. Result would looks like this:"


<IfModule mod_dir.c>
DirectoryIndex index.html index.wml index.cgi index.shtml index.jsp index.js index.jp index.php5 index.php4 index.php3 index.php index.phtml ndex.htm default.htm default.html home.htm
</IfModule>


This to allow index.php5 as index file.

Continue editing. Find the "AddType application/x-httpd-php .phtml" and after it add this:


Action application/x-httpd-php5 "/cgi-sys/php5"
AddHandler application/x-httpd-php5 .php5



Check if we could find this line "ScriptAlias /cgi-sys/ /usr/local/cpanel/cgi-sys/"
If not - add it or our directive will not work. By default cPanel add this line. Just to warn you.

Verify that you not broke the Apache config by running:

service httpd configtest

You SHOULD to get "Syntax OK" at the end and possible some minor warnings about "NameVirtualHost directive" - it is OK.
Warning: if you get ERROR - DO NOT RESTART APACHE AND LOCATE THE ISSUE. Otherwise Apache will not start at all!

When you make sure it is OK restart the Apache:

/scripts/restartsrv_httpd
service httpd restart

(do both and sometimes apache doesn't restart cleanly)


now any files with .php5 will be parsed by php5. .php is still parsed through php 4. your php 4 install is left totally unchanged.

* note - credit goes to ispro on cpanel's forum - i copied parts of this from his guide - but i also added my own automation for the configure command generation as well as updated it (php versions)

HTH.

elmwood
10-11-2006, 01:20 AM
On many Web sites, I see that one can add the following to their .htaccess file to automatically use PHP5 for scripts just named .php in that directory:

AddHandler application/x-httpd-php5 .php

I managed to install PHP5 per the instructions, but adding the line in .htaccess, PHP5 scripts with files having the .php suffix (Mediawiki, for example) still don't run.

Any advice on how to get it to work? Simply remaning suffixes to .php5 won't work in many cases.

elix
10-11-2006, 03:08 PM
AddHandler application/x-httpd-php5 .php

should work just fine

does .php5 work?

elmwood
10-12-2006, 12:39 AM
Is there a way to test it in the shell? Thanks.

elix
10-12-2006, 06:14 AM
Is there a way to test it in the shell? Thanks.
/usr/local/php5/bin/php -v

vps-vince
10-12-2006, 08:07 PM
Hi elix,
Have you seen or tested the following script to do this on the cPanel forums?

http://forums.cpanel.net/showthread.php?t=45926

I also wrote a small script to automatically install PHP5 as a CGI using the same configuration as the already installed PHP4 module. Not really released to public (I just use it on my own servers to keep PHP4 and PHP5 running along side eachother), but here ya go anyway. I'm planning on putting it in my LES program soon, anyway.

#!/bin/sh
#
# Copyright (C) 2005 Richard Gannon. All rights reserved.
#
# Author: Richard Gannon
#
# This script will install PHP5 as a CGI on a cPanel server using the same configure
# selections as the already built PHP4. You can have PHP scripts utilize the PHP5
# engine by using the .php5 extension.
#
# Version 1.1
#
##

PHP_VERSION=5.0.5

WGET=/usr/bin/wget
GREP=/bin/grep
TAR=/bin/tar
AWK=/bin/awk

cd /usr/src
$WGET -O php.tbz2 http://php.net/get/php-${PHP_VERSION}.tar.bz2/from/this/mirror
$TAR -xjvf php.tbz2
rm -f php.tbz2
$WGET http://choon.net/opensource/php/php-${PHP_VERSION}-mail-header.patch
cd php-${PHP_VERSION}
patch -p1 < /usr/src/php-${PHP_VERSION}-mail-header.patch
rm -f /usr/src/php-${PHP_VERSION}-mail-header.patch

if [ -e /usr/local/bin/php ]; then
PHP=/usr/local/bin/php
else
PHP=/usr/bin/php
fi
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

PHP5CONF=`$GREP php5.conf /usr/local/apache/conf/httpd.conf`
if [ "$PHP5CONF" = "" ]; then
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
echo "Include /usr/local/apache/conf/php5.conf" >> /usr/local/apache/conf/httpd.conf
fi

CONFIGTEST=`/etc/init.d/httpd configtest | $GREP -m1 Syntax | $AWK '{print $2 }'`
if [ "$CONFIGTEST" = "OK" ]; then
echo "Restarting Apache now..."
/etc/init.d/httpd restart
echo "Done. Enjoy PHP5!"
else
echo "There may have been a problem with this installation."
echo "Please check the httpd.conf for syntax with '/etc/init.d/httpd configtest'"
fi

exit 0

- Vince

elix
10-12-2006, 09:08 PM
Hi elix,
Have you seen or tested the following script to do this on the cPanel forums?

http://forums.cpanel.net/showthread.php?t=45926



- Vince
It looks like it should work fine...I have not used it but it's worth a shot...

elmwood
10-14-2006, 08:34 PM
/usr/local/php5/bin/php -v

On my VPS, following the instructions, it ended up as /usr/local/php5/bin/php5.

I tested it, and PHP5 did seem to work. I just can't use it.

root@host [~]# /usr/local/php5/bin/php5 -v
PHP 5.1.6 (cli) (built: Oct 11 2006 00:25:40)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

In the cpanel directory:

root@host [/usr/local/cpanel/cgi-sys]# /usr/local/cpanel/cgi-sys/php5 -v
PHP 5.1.6 (cli) (built: Oct 11 2006 00:25:40)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

elix
01-26-2007, 06:50 PM
Sorry to take so long to reply but:

1 - i fixed the issue that elmwood experienced.
2 - i updated this to reflect 5.2.0 - latest php 5 version

nsetiono
03-31-2007, 06:33 AM
i had following your method to installing php 5

but still got error msg when try to running .php5 file

================================================== ======
cgi suexec is running

permission is fine

installing php 5 was fine too

Build complete.
(It is safe to ignore warnings about tempnam and tmpnam).

Installing PHP SAPI module: cgi
Installing PHP CGI into: /usr/local/php5/bin/
Installing build environment: /usr/local/php5/lib/php/build/
Installing header files: /usr/local/php5/include/php/
Installing helper programs: /usr/local/php5/bin/
program: phpize5
program: php-config5
Installing man pages: /usr/local/php5/man/man1/
page: phpize5.1
page: php-config5.1
Installing PEAR environment: /usr/local/php5/lib/php/
[PEAR] Console_Getopt - already installed: 1.2
[PEAR] Archive_Tar - already installed: 1.3.2
[PEAR] PEAR - already installed: 1.4.11
Wrote PEAR system config file at: /usr/local/php5/etc/pear.conf
You may want to add: /usr/local/php5/lib/php to your php.ini include_path
Installing PDO headers: /usr/local/php5/include/php/ext/pdo/

i dont know what error again http://forums.cpanel.net/images/smilies/frown.gif

the error still same

[Sat Mar 31 06:13:53 2007] [notice] Apache/1.3.37 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7e-p1 PHP-CGI/0.1b configured -- resuming normal operations
[Sat Mar 31 06:13:53 2007] [notice] suEXEC mechanism enabled (wrapper: /usr/local/apache/bin/suexec)
[Sat Mar 31 06:13:53 2007] [notice] Accept mutex: flock (Default: flock)
[Sat Mar 31 06:14:20 2007] [error] [client 202.47.64.250] Premature end of script headers: /usr/local/cpanel/cgi-sys/php5
[Sat Mar 31 06:14:20 2007] [error] [client 202.47.64.250] File does not exist: /home/uletbulu/public_html/500.shtml

elix
04-02-2007, 10:12 PM
nsetiono,

I haven't been able to replicate your issue, but would have to look at your server to see what may be happening.

Just as a note I have performed the exact steps as above on over 20 servers with no problems.

nsetiono
04-03-2007, 10:42 AM
i had rebuild my apache without suexec module and disable suexec

and the error is changed into this

Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.
Warning: User directive in <VirtualHost> requires SUEXEC wrapper.
Warning: Group directive in <VirtualHost> requires SUEXEC wrapper.

its seem i must enable suexec wrapper :)
because if suexec disabled even php 4 cannot work

my server running freebsd 6.2

please help