Go Back   cPanel Forums > cPanel® and WHM® (for Linux® and FreeBSD® Servers) > cPanel and WHM Discussions

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-29-2005, 06:09 PM
Registered User
 
Join Date: Apr 2004
Posts: 604
ispro is on a distinguished road
HOW-TO: Apache + (phpsuexec, not required) + php4 (mod_php4 or cgi) + php5 (cgi) *NEW

06/20/2007 - Fixed the command to copy php5 CGI binary as it is named as php5-cgi since 5.2.1
06/15/2007 - HOW-TO updated with new php5 wrapper which works on per-directory basis, also php5 versions updated to 5.2.3

This setup works!

I'm using Apache 1.3.37 + phpsuexec coming with cPanel + custom php 4.4.7 compiled as cgi (actually you may use the Apache Update via WHM to compile working php4 in cgi mode/phpsuexec) + custom php 5.2.3 compiled as cgi (it is easy to do as well, I will explain)

php5 works the same as php4 and it saves the permissions and etc. E.g. no problems with nobody as well.

HOW-TO

1. Make sure you has Apache installed and workind with php4. It doesn't matter if you run mod_php4 or php4/phpsuexec, but I recommend to have phpsuexec based install (Warning: if you are running mod_php4 and would like to switch to phpsuexec, read the threads in this forum or you may end up with numerous broken scripts!);

2. You would need to compile php 5. To do this use the SSH sessing logged as root.
Then execute preparation commands (based on cPanel for better compatibility):
Code:
/scripts/checkccompiler
rm -rf /home/cpphpbuild
mkdir /home/cpphpbuild
cd /home/cpphpbuild
wget http://layer1.cpanel.net/buildapache/1/php-5.2.3.tar.gz
tar xfzv php-5.2.3.tar.gz
cd php-5.2.3
Make sure that we do enabled Sendmail support:
Code:
echo "#define HAVE_SENDMAIL 1" >> /home/cpphpbuild/php-5.2.3/main/php_config.h
It is recommended to apply the mail-header patch which allows to track the script which sent an email. You may skip this step.
Code:
wget http://choon.net/opensource/php/php-5.2.3-mail-header.patch
patch -p1 < /home/cpphpbuild/php-5.2.3/php-5.2.3-mail-header.patch
Then one of the most important steps. It is the configuring of the php. It would be better if you undestand these options. You may use the configure from your existing php. To get them type the following:
Code:
php -i | grep configure | sed "s/'//g" | sed "s/'//g"
As you may see there are two same sed, however they are diferent! The second single quote should looks like & # 0 3 9 ; (without spaces!!) and this is for some cases when single quote sign shown as the code.
You will get the almost clean configure you are currently using. The several important hints on this.
a) REMOVE the "--with-apxs=/usr/local/apache/bin/apxs" from the line. We are going to compile CGI version and it WILL broke the Apache!

b) Make sure you have the following prefixes and suffixes to install to the proper directories - otherwise currently installed php could be broken:
--prefix=/usr/local/php5 --exec-prefix=/usr/local/php5 --program-suffix=5

c) Add the necessary options for proper CGI redirects from Apache:
--enable-force-cgi-redirect --enable-discard-path

The result line will looks like this (please, do not use it - it has no CURL and PostgreSQL support - you better to follow steps above):
Code:
./configure --prefix=/usr/local/php5 --exec-prefix=/usr/local/php5 --program-suffix=5 --with-xml --enable-bcmath --enable-calendar --enable-ftp --with-gd --enable-exif --with-jpeg-dir=/usr --with-png-dir=/usr --with-xpm-dir=/usr/X11R6 --with-imap --with-imap-ssl --with-kerberos --enable-mbstring --with-mbstring=all --enable-mbstr-enc-trans --with-mcrypt --with-mhash --enable-magic-quotes --with-mysql=/usr --with-openssl --enable-discard-path --with-pear --enable-sockets --enable-track-vars --with-ttf --with-freetype-dir=/usr --enable-versioning --with-zlib --with-pspell --with-gettext --enable-inline-optimization --disable-debug --enable-force-cgi-redirect --enable-discard-path
So, we are ready to start the compiling. Execute "make install" and it starts...
If the process fails for any reason, carefully read the errors - usually they are self-explaining. In MOST cases errors are because of the inproper configure params.

Then run the cPanel script to complete:
/scripts/findphpversion

The compiled version of php should be copied to the cPanel cgi-sys:
Code:
cp -f /usr/local/php5/bin/php-cgi5 /usr/local/cpanel/cgi-sys/php5
chown root:wheel /usr/local/cpanel/cgi-sys/php5
Our installation has no php.ini file yet. On MOST systems Zend Optimizer installed. In this case you may just create the symlink:
Code:
ln -s /usr/local/Zend/etc/php.ini /usr/local/php5/lib/php.ini
Otherwise copy the default php.ini and edit it if needed:
Code:
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
It is recommended to add the following line to the php.ini at the bottom (it is a MUST if you compile php4 instead php5!). Note that this line will broke regular php4. As a common rule - if you are using the same php.ini, do not add this line:
Code:
cgi.fix_pathinfo        = 1     ; needed for CGI/FastCGI mode
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:
Code:
<IfModule mod_dir.c>
DirectoryIndex index.html index.wml index.cgi index.shtml index.jsp index.js index.jp index.php5 iindex.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:
Code:
Action application/x-httpd-php5 "/cgi-sys/php5"
AddHandler application/x-httpd-php5 .php5
This is the directives for Apache to use own php5 for files with extensions .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.

Save the file and quit.

Verify that you not broke the Apache config by running:
Code:
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:
Code:
service httpd stop
service httpd startssl
Check that Apache come ok:
Code:
lynx --dump http://localhost/whm-server-status;
It will show you the Apache status.

Well, I should congratulate you - you have done it!

To test php5 upload the simple php file with the following content to any of your sites and name this file phpinfo.php AND ANOTHER COPY phpinfo.php5:
Code:
<?php
phpinfo();
?>
Then launch browser and point to phpinfo.php file first to see that php4 still OK, then open phpinfo.php5 to see that php5 is OK.

DONE!

PHP5 WRAPPER:
As php5 compiled in the cgi mode customers cannot to use .htaccess directives like php_admin, php_value, php_flag. In phpsuexec setup (for main php) it is overridden by allowing customers place custom php.ini with the variables.

However if you build the php5 as the secondary php it will not have such ability. So how to solve it? To write very simple wrapper to pass php.ini line of the current directory if exists.

The steps to be done after php5 setup.

Moving php5 binary:
Code:
mv /usr/local/cpanel/cgi-sys/php5 /usr/local/cpanel/cgi-sys/php5.bin
Then creating wrapper file in the /usr/local/cpanel/cgi-sys/php5 with the following content:
Code:
#!/bin/bash

# This will fake the name & path and hide the /usr/local/cpanel/cgi-sys/php5 path!
export SCRIPT_NAME=$REQUEST_URI
export SCRIPT_FILENAME=$PATH_TRANSLATED
export PWD=`echo $PATH_TRANSLATED|egrep -o "(.*?/)"`

if [ -f "$PWD/php.ini" ]; then
exec /usr/local/cpanel/cgi-sys/php5.bin -c $PWD
else
exec /usr/local/cpanel/cgi-sys/php5.bin
fi
Save the file and change the permissons:

Code:
chown root:wheel /usr/local/cpanel/cgi-sys/php5*;
chmod 755 /usr/local/cpanel/cgi-sys/php5*;
We are done! By default php5 will use the global php.ini, but if the customer has the own php.ini in its folder php5 will use it instead (corrected on 06/15/2007, before php.ini should be placed at public_html only).

Simple as that!

ADDONS:
If you need to use php5 for applications hardcoded with .php extensions you could to add the magic line to the VirtualHost directive of this account:
AddHandler application/x-httpd-php5 .php .php4 .php3 .phtml
(.php5 already using php5, but you may add it if you wish)

This will redirect all php, php3, php4 and php5 (as it set default globally) to the php5.

If you need to leave the option of running php4 on .php4 files do this:
AddHandler application/x-httpd-php5 .php .php3 .phtml .php5

But for those lazy folks there are an option to have these AddHandlers in the .htaccess files!
Just add the respective line (example, with no quotes: "AddHandler application/x-httpd-php5 .php .php4 .php3 .phtml") to the .htaccess and this directory and all its subdirectories would be able to use the php5 for chosen files!

This is awesome when you need to test some scripts. In this way create two directories:
/public_html/directory1
/public_html/directory2
And in the directory2 place .htaccess with:
AddHandler application/x-httpd-php5 .php .php4 .php3 .phtml

As a result you run php4 on .php in the directory1 and run php5 on .php in the directory2!

So it is very flexible and it all depends on how you would like to process php.

P.S. Anyone who would like this setup, but not sure how to proceed - I may perform the compile works for your server(s) at a low rate on the working server with no service interruption. mod_php4 + php5/cgi combo will works as well (tested). PM me for information.
__________________
Reliable web-hosting, good resellers plans, web-design.
ISProHosting.com

Last edited by ispro; 06-27-2007 at 03:52 AM. Reason: Update.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-30-2005, 09:15 PM
rhenderson's Avatar
Registered User
 
Join Date: Apr 2005
Location: Oklahoma
Posts: 722
rhenderson is on a distinguished road
Isn't there a way through .htaccess or a local php.ini to set it where you would not have to rename all the files to .php5 ??

It is not to hard to rename but when includes in the source are linked to a php file instead of php5 it breaks
__________________
Regards,
Randy
Affordable Web Hosting
_________________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-31-2005, 01:02 AM
Registered User
 
Join Date: Apr 2004
Posts: 604
ispro is on a distinguished road
Quote:
Originally Posted by rhenderson
Isn't there a way through .htaccess or a local php.ini to set it where you would not have to rename all the files to .php5 ??

It is not to hard to rename but when includes in the source are linked to a php file instead of php5 it breaks
ANSWER UPDATED! Refer to the original post (first post on this thread), at the bottom.
__________________
Reliable web-hosting, good resellers plans, web-design.
ISProHosting.com

Last edited by ispro; 11-02-2005 at 09:39 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-02-2005, 08:47 AM
Registered User
 
Join Date: Nov 2002
Posts: 242
web12
hmm not sure what ive done wrong here.

must say I completed this no problem at all on 1 server, then the second one seemed to have compiled without any errors, but when I run the phpinfo script for php5 I get

No input file specified.

in the browser window.

Ive re-traced my steps and all seems correct. anyone got any ideas?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-02-2005, 09:03 AM
Registered User
 
Join Date: Apr 2003
Posts: 130
astopy is on a distinguished road
Quote:
Originally Posted by rhenderson
Isn't there a way through .htaccess or a local php.ini to set it where you would not have to rename all the files to .php5 ??

It is not to hard to rename but when includes in the source are linked to a php file instead of php5 it breaks
You should just be able to put this in .htaccess to enable it on a per-directory basis:
Code:
AddType application/x-httpd-php5 .php
I haven't set any of this up yet though, so I can't test it myself.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 11-02-2005, 09:12 AM
Registered User
 
Join Date: Jan 2005
Posts: 1,877
webignition is on a distinguished road
Quote:
Originally Posted by Odhinn
You should just be able to put this in .htaccess to enable it on a per-directory basis:
Code:
AddType application/x-httpd-php5 .php
I haven't set any of this up yet though, so I can't test it myself.
Can anyone confirm if this does work within a .htaccess file on a per-directory basis?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 11-02-2005, 09:15 AM
Registered User
 
Join Date: Apr 2004
Posts: 604
ispro is on a distinguished road
Quote:
Originally Posted by Odhinn
You should just be able to put this in .htaccess to enable it on a per-directory basis:
Code:
AddType application/x-httpd-php5 .php
I haven't set any of this up yet though, so I can't test it myself.
You are a LITTLE wrong.

You should to use AddHandler for php as cgi:
AddHandler application/x-httpd-php5 .php .php4 .php3 .phtml

Not forget that this works on recurse basis. E.g. for every subdirectory under the main subdirectory.

This is confirmed thing on Apache + phpsuexec + php4 cgi + php5 cgi
__________________
Reliable web-hosting, good resellers plans, web-design.
ISProHosting.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 11-02-2005, 09:26 AM
Registered User
 
Join Date: Apr 2004
Posts: 604
ispro is on a distinguished road
Quote:
Originally Posted by web12
hmm not sure what ive done wrong here.

must say I completed this no problem at all on 1 server, then the second one seemed to have compiled without any errors, but when I run the phpinfo script for php5 I get

No input file specified.

in the browser window.

Ive re-traced my steps and all seems correct. anyone got any ideas?
Run the following:
/usr/local/php5/bin/php5 -i |grep configure

I bet that you have NO '--enable-force-cgi-redirect' '--enable-discard-path'

This is the common issue.
I may take a look at your case for free. PM me.

P.S. I have slightly updated the HOWTO in the VirtualHost section.
__________________
Reliable web-hosting, good resellers plans, web-design.
ISProHosting.com

Last edited by ispro; 11-02-2005 at 10:33 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 11-02-2005, 12:23 PM
Registered User
 
Join Date: Nov 2002
Posts: 242
web12
ok... problem fixed!

Not sure why though, but if I put the phpinfo page into a different site on the same server it works as expected.... strange that the php extension would work fine but the php5 wouldnt in the old account though.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 11-02-2005, 12:26 PM
Registered User
 
Join Date: Apr 2004
Posts: 604
ispro is on a distinguished road
So, the issue in the Apache settings for chosen VirtualHost?..

You may PM me these settings just for make sure...

P.S. Please, remove ALL your posts about that problem like I did to clean up this thread...
Anyway, your issue is not reproduceable and this wouldn't be useful for others...
__________________
Reliable web-hosting, good resellers plans, web-design.
ISProHosting.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 11-02-2005, 12:32 PM
Registered User
 
Join Date: Nov 2002
Posts: 242
web12
OK, messages all tidied up.

No need to worry about the other virtualhost as its just for the server hostname entry. The domain I actually wanted this to work on is working, so thats great!

Thanks again for your time, you are a star.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 11-02-2005, 10:28 PM
rhenderson's Avatar
Registered User
 
Join Date: Apr 2005
Location: Oklahoma
Posts: 722
rhenderson is on a distinguished road
Quote:
Originally Posted by rhenderson
Isn't there a way through .htaccess or a local php.ini to set it where you would not have to rename all the files to .php5 ??

It is not to hard to rename but when includes in the source are linked to a php file instead of php5 it breaks
Actually I did it the other way around since I was running php5 already and followed the instructions to try to get php4 to work as a cgi by changing the names from php5 to php4 lol It almost worked... I get this error when running a .php4 file

Warning: Unexpected character in input: '' (ASCII=21) state=1 in /usr/local/cpanel/cgi-sys/php4 on line 1183

Warning: Unexpected character in input: '' (ASCII=8) state=1 in /usr/local/cpanel/cgi-sys/php4 on line 1183

Warning: Unexpected character in input: '' (ASCII=2) state=1 in /usr/local/cpanel/cgi-sys/php4 on line 1183

Parse error: parse error, unexpected T_STRING in /usr/local/cpanel/cgi-sys/php4 on line 1183

Any ideas?
__________________
Regards,
Randy
Affordable Web Hosting
_________________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 11-02-2005, 11:09 PM
rhenderson's Avatar
Registered User
 
Join Date: Apr 2005
Location: Oklahoma
Posts: 722
rhenderson is on a distinguished road
Okay fixed the above if anyone else has problems with doing the same setup I did which was php4 as cgi

In the /usr/local/php4/lib/php.ini right under

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

I added

cgi.fix_pathinfo=1


All is good
__________________
Regards,
Randy
Affordable Web Hosting
_________________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 11-03-2005, 02:44 AM
Registered User
 
Join Date: Apr 2004
Posts: 604
ispro is on a distinguished road
You did found solution before I saw your question

Yes, it is a correct way to fix these issues. It is also recommended to add to php5 (cgi) as well. I updated the HOWTO on this.
__________________
Reliable web-hosting, good resellers plans, web-design.
ISProHosting.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 11-03-2005, 09:01 AM
Registered User
 
Join Date: Apr 2004
Posts: 604
ispro is on a distinguished road
Quote:
Originally Posted by web12
Hi

I have a small issue where one of the extensions I need compiled with php5 wont load, even though I have it in my configure line.

The extension is xmlrpc and my configure line has --with-xmlrpc but that doesnt go through to my phpinfo page and my script is also reporting an issue with it.

any ideas?
You need to check the configure process. During it you will probably see the reason.
__________________
Reliable web-hosting, good resellers plans, web-design.
ISProHosting.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 10:12 AM.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© cPanel Inc