Php5 and Php4 Together with suPHP

This post follow my previous one PHP5 CGI & CLI with an existing PHP4 Modules installation here http://www.interworx.com/forums/showthread.php?t=1630

Here we will show you how to install php5, suphp and configure your box to have php4 and php5 running on the same box.

This will give you the ability to easily have on an interworx box php running as:

  • php4 as module or cgi
  • php5 as CGI
  • More security (mod suPHP in paranoid mode + suexec)

You already have php4 installed as module
You want to install php5 as CGI and allow your users to run php5 scripts as CGI and php4 scripts as CGI too.

1/ First install the php5-cli-cgi RPM.
This rpm install only the cli and cgi version of php5.
All informations are there : http://www.interworx.com/forums/showthread.php?t=1630

2/Now install suPHP

The config file of mod_suphp.conf in /etc/httpd/conf.d/mod_suphp

mod_suphp

LoadModule suphp_module modules/mod_suphp.so

<IfModule mod_suphp.c>
suPHP_Engine off
</IfModule>

Vhost config file of the user who’d like to have php5 and php4 in /etc/httpd/conf.d/domain.conf

…/…

ErrorLog /home/account/var/domain/logs/error.log
CustomLog /home/account/var/domain/logs/transfer.log combined

Insert suPHP Stuff here

AddHandler x-httpd-php .php
AddHandler x-httpd-php5 .php5
suPHP_Engine on
suPHP_UserGroup user group
suPHP_AddHandler x-httpd-php5 .php5
suPHP_AddHandler x-httpd-php .php

<Files *.php>
suPHP_ConfigPath /etc
</Files>
<Files *.php5>
suPHP_ConfigPath /etc/php5
</Files>

cgi: 1 don’t edit between this and the “end cgi” comment below

…/…

and finaly update the suphp.conf in /etc

…/…

; Security options
allow_file_group_writeable=true
allow_file_others_writeable=false
allow_directory_group_writeable=true
allow_directory_others_writeable=false

…/…

;Umask to set, specify in octal notation
umask=0077

…/…

[handlers]
;Handler for php-scripts
x-httpd-php=php:/usr/bin/php
x-httpd-php5=php:/usr/bin/php5

…/…

By default all file in the docroot ending by .php5 will be treat by suPHP handlers and the php5 binary, and all file ending by .php will be treat by suPHP handlers the php4 binary

If your users want to have all their files ending by .php treat by suPHP and php5 bianry just tell them to add in an .htaccess file this (or just update their vhost conf file by removing php4 stuff and changing php5 by these lines)

AddHandler x-httpd-php5 .php
AddType application/x-httpd-php5 .php

Finally we have php4 and php5 for this vhost. For example, here is the two phpinfo on the same domain
php4 : http://clust01-carat01.carat-hosting.com/phpinfo.php
php5 : http://clust01-carat01.carat-hosting.com/phpinfo.php5

Hope this will help

Pascal

Carat Hosting : H?bergement de sites Internet

Pascal, thanks for this. This is something I have wanted to do for a while, but have just been putting it off since it wasn’t a very high priority.

Couple questions…

Default Iworx setup has the end user PHP 4 as a CGI or a module or both?

$ php -v
PHP 4.3.11 (cgi) (built: Sep 27 2005 10:39:25)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
    with the ionCube PHP Loader v2.5, Copyright (c) 2002-2005, by ionCube Ltd.

[QUOTE=pascal;10805]1/ First install the php5-cli-cgi RPM.
This rpm install only the cli and cgi version of php5.
All informations are there : http://www.interworx.com/forums/showthread.php?t=1630[/quote]
Won’t this overwrite the current default Iworx PHP 4 install? Or it will just overwrite the default CGI install, but the websites are really using the module (meaning the answer to the first question was “both”).

Default Iworx setup has the end user PHP 4 as a CGI or a module or both?

By default the default iworx setup the end user has PHP?4 as Module.

After the install default iworx user still has PHP4 as module.

To change this you have to add few lines in the vhost of the user to add suPHP stuff.
You might choose between :
php4 as CGI alone,
php5 as CGI alone;
PHP4 as CGI and PHP5 as CGI

$ php -v
PHP 4.3.11 (cgi) (built: Sep 27 2005 10:39:25)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
    with the ionCube PHP Loader v2.5, Copyright (c) 2002-2005, by ionCube Ltd.

Won’t this overwrite the current default Iworx PHP 4 install? Or it will just overwrite the default CGI install, but the websites are really using the module (meaning the answer to the first question was “both”).

We’ve made a special RPM. This rpm install php5 as CGI and CLI, but doesn’t install the DSO module. More, this rpm won’t overwrite existing php4 installation. Indeed, all php5 files are located in others places (see post http://www.interworx.com/forums/showthread.php?t=1630)

So NO DEFAULT install are impacted.

It installs php5 as CGI and CLI at others locations and after you play with su?PHP to choose what you want !! :slight_smile:

php4 as MODULE alone = No change in the vhost, it’s the default
php5 as CGI alone (the user want php5 and nothing else) = In the vhost

AddHandler x-httpd-php5 .php
suPHP_Engine on
suPHP_ConfigPath /etc/php5/ #ou /home/account/
suPHP_UserGroup user group
suPHP_AddHandler x-httpd-php5 .php

PHP4 as CGI and PHP5 as CGI (the user want both php4 and php5 with .php5 and .php) =
In the vhost

AddHandler x-httpd-php .php
AddHandler x-httpd-php5 .php5
suPHP_Engine on
suPHP_UserGroup user group
suPHP_AddHandler x-httpd-php5 .php5
suPHP_AddHandler x-httpd-php .php

<Files *.php>
suPHP_ConfigPath /etc
</Files>
<Files *.php5>
suPHP_ConfigPath /etc/php5
</Files>

If the user want all files *.php as php5 and *.php4 as php4 no problem. He might write an htaccess file with

AddHandler x-httpd-php .php4
AddHandler x-httpd-php5 .php
suPHP_AddHandler x-httpd-php5 .php
suPHP_AddHandler x-httpd-php .php4

etc…

So everything is possible !!

We use all these kinds of config for some users and it work just great !!

Pascal

Carat Hosting : H?bergement de sites Internet

i want all files ending in php to use php5 and not the defualt at present php uses php4.

what do i have to add in the vhost, tried all the above only one i could get working was
this one.

php4 as CGI and php5 as CGI

AddHandler x-httpd-php .php
AddHandler x-httpd-php5 .php5
suPHP_Engine on
suPHP_UserGroup user group
suPHP_AddHandler x-httpd-php5 .php5
suPHP_AddHandler x-httpd-php .php

<Files *.php>
suPHP_ConfigPath /etc
</Files>
<Files *.php5>
suPHP_ConfigPath /etc/php5
</Files>

also if i want php4 as a module and php5 as a CGI
what do i need to put in vhost

thank you

You can’t have for the same domain php4 as module and php5 as cgi, if you need both for one domain then both will be cgi with suPHP

Here is how we use it
In the vhost

suPHP_Engine on
suPHP_UserGroup account account
suPHP_AddHandler x-httpd-php5 .php
suPHP_AddHandler x-httpd-php .php
suPHP_ConfigPath /etc/php5
SetEnv PHPRC /etc/php5/
AddHandler x-httpd-php5 .php
AddHandler x-httpd-php5 .phtml
AcceptPathInfo On

Here, by default the domain will use PHP5

You can switch to php4 by just adding a line in an htaccess file
Ok tell we have the directory html/ which will use php5 and in html an other dir html/app/ which will use php4

So in html, by default it will be php5 (because in the vhost we set it to php5, we’d could set it to php4)

In html/app/ create an htaccess file with this line

AddHandler x-httpd-php .php .php4 .php3

That’s all :slight_smile:

You could set PHP5 with

AddHandler x-httpd-php5 .php .php4 .php3

Note that you could define a php.ini file for this domain

suPHP_ConfigPath /home/account/domain.com
SetEnv PHPRC /home/account/domain.com

Finaly be sure to have set suphp.conf
Ours looks like this

[global]
;Path to logfile
logfile=/var/log/httpd/suphp.log
;Loglevel
loglevel=info
;User Apache is running as
webserver_user=apache
;Path all scripts have to be in
docroot=/
; Security options
allow_file_group_writeable=false
allow_file_others_writeable=false
allow_directory_group_writeable=false
allow_directory_others_writeable=false
;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=false
;Send minor error messages to browser
errors_to_browser=false
;PATH environment variable
env_path=/bin:/usr/bin:/usr/local/bin
;Umask to set, specify in octal notation
umask=0077
; Minimum UID
min_uid=500
; Minimum GID
min_gid=500

[handlers]
;Handler for php-scripts
x-httpd-php=php:/usr/bin/php-cgi

;Handler for PHP5-scripts
x-httpd-php5=php:/usr/bin/php5

;Handler for CGI-scripts
x-suphp-cgi=execute:!self

If you have a pbm check /var/log/httpd/suphp.log

Paul

I forgot to tell you that in your config you can’t have two AddHandler, Apache will take the last one. But you can have 2 suPHP_AddHandler

Also, we did a patch in suPHP to allow suPHP_AddHandler in a vhost config file !
By default suPHP doesn"'t accept this command in a vhost !

I don’t remember where I give our new SRPM, but I give it somewhre in the forum
If you need it ask me

Paul

here is the last version suPHP as rpm/srpm with our the patches applied and CENTOS5 compliant !
http://www.interworx.com/forums/showthread.php?t=2680

for example

With this config we have PHP5 here (all files with .php)
http://www.netipro.com/phpinfo.php

And PHP4 here (all files with .php)
http://www.netipro.com/php4/phpinfo.php

Paul

Hi
That all working ok thank you
found a couple of errors that i had not set correctly, i had /usr/bin/php missed the cgi part.

[handlers]
;Handler for php-scripts
x-httpd-php=php:/usr/bin/php-cgi

When adding in a .htaccess to a directory to change it to php4 i get an
500 internal server error for some reason.

You can switch to php4 by just adding a line in an htaccess file
Ok tell we have the directory html/ which will use php5 and in html an other dir html/app/ which will use php4

So in html, by default it will be php5 (because in the vhost we set it to php5, we’d could set it to php4)

In html/app/ create an htaccess file with this line

Quote:
AddHandler x-httpd-php .php .php4 .php3

[quote=bear;15219]Hi
That all working ok thank you
found a couple of errors that i had not set correctly, i had /usr/bin/php missed the cgi part.

When adding in a .htaccess to a directory to change it to php4 i get an
500 internal server error for some reason.[/quote]

cool :wink:

Well for the 500 internal server error it’s surely due to a chmod/chown error.

Indeed as you can see in the suphp.conf file there the directory AND the file can’t be writable by group and others.

Be sure you have a 755 chmod, or 700 if you use supPHP and the php cgi part (as suphp will execute the file under the user/group of the domain owner)

Be also sure to a chown set to the owner of the domain

Did you use our suPHP rpm ?

Could have a look at the logs in /var/log/httpd/suphp.log and in /home/account/var/domain.com/logs/error.log and/or in /var/log/httpd/error.log

Also check that your vhost accept the .htaccess file, you should have something like this

<Directory /home/account/domain.com/html>
AllowOverride All
</Directory>

Paul

[quote=bear;15219]Hi
When adding in a .htaccess to a directory to change it to php4 i get an
500 internal server error for some reason.[/quote]

Hi Bear

Is that ok now ?
What was the problem ?

Paul

Hi

php5 works fine.

not fully sorted yet on changing php5 to php4, the 500 error has gone now.

set this in vhost to off [SIZE=1]php_admin_flag engine off[/SIZE]

[SIZE=1]The php-cgi i dont have in usr/bin/ and reset that back to usr/bin/php[/SIZE]
[SIZE=1]may be thats my problem[/SIZE]

 
[handlers]
;Handler for php-scripts
x-httpd-php=php:/usr/bin/php-cgi

[SIZE=1]htaccess now works and does not give a 500 error, i can load a info,php and see that php has changed from php5 default to php4.[/SIZE]
[SIZE=1]but the php scripts are not loading/working only HTML works when using the htaccess [/SIZE]

 
AddHandler x-httpd-php .php .php4 .php3