How To Set Up suPHP With PHP4 And PHP5 - Page 3

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Sun, 2006-06-11 09:01. ::

7 suPHP and PHP5

In this section we install PHP5 and make it work with suPHP. The PHP4-CGI will not be removed by this!


7.1 Install PHP5

As there is no official PHP5 package for Debian Sarge, we must install third-party packages. There are some repositories like backports.org or dotdeb.org that provide such packages. In the following, we will install the PHP5-CGI package from dotdeb.org.

Add the following lines to /etc/apt/sources.list (don't remove the other repositories!):

vi /etc/apt/sources.list

deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all

Then run

apt-get update

Install php5-cgi like this:

apt-get install php5-cgi


7.2 Configure Apache

The headline is a little bit misleading. Actually we don't have to change the Apache configuration. We still have our vhost like above:

<VirtualHost 1.2.3.4>
ServerName www.example.com
ServerAdmin webmaster@example.com
DocumentRoot /var/www

suPHP_Engine on
suPHP_UserGroup testuser test
AddHandler x-httpd-php .php .php3 .php4 .php5
suPHP_AddHandler x-httpd-php
</VirtualHost>

All we have to do to make our www.example.com vhost use PHP5 is change the x-httpd-php line in /etc/suphp.conf. It must now point to our php5-cgi binary:

vi /etc/suphp.conf

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

You don't even have to restart Apache! Now go to http://www.example.com/info.php again with your browser, and you should see that PHP5 is running:


8 PHP4 And PHP5 At The Same Time

Now we have both php4-cgi and php5-cgi installed on our server. If you have multiple vhosts on your server, you can have one use PHP4 and the other use PHP5 at the same time. To do this, we define two handlers in /etc/suphp.conf. Edit the [handlers] section so that it looks like this:

vi /etc/suphp.conf

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

If you want to use PHP4 in your vhost, use the x-httpd-php handler:

<VirtualHost 1.2.3.4>
ServerName www.example.com
ServerAdmin webmaster@example.com
DocumentRoot /var/www

suPHP_Engine on
suPHP_UserGroup testuser test
AddHandler x-httpd-php .php .php3 .php4 .php5
suPHP_AddHandler x-httpd-php
</VirtualHost>

If you want to use PHP5, use the x-httpd-php5 handler:

<VirtualHost 1.2.3.4>
ServerName www.example.com
ServerAdmin webmaster@example.com
DocumentRoot /var/www

suPHP_Engine on
suPHP_UserGroup testuser test
AddHandler x-httpd-php5 .php .php3 .php4 .php5
suPHP_AddHandler x-httpd-php5
</VirtualHost>

Don't forget to restart Apache after the changes to your vhosts:

/etc/init.d/apache2 restart


9 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Wed, 2006-06-14 20:57.
So why would someone use this rather than suexec?
Submitted by Anonymous (not registered) on Mon, 2006-06-12 22:30.
Now we must edit src/apache2/mod_suphp.c because otherwise you'll get an error like this one
Wrong approach. The developer of SuPHP intentionally didn't allow the SuPHP_AddHandler directive in some blocks, like the global Apache configuration or plain VirtualHost-Blocks. Instead of configuring your Apache httpd correctly you patch the SuPHP source. Maybe you want to read about the Location- and Directory-directives in the Apache manual?
Submitted by admin (registered user) on Mon, 2006-06-12 23:51.
Then the Location and Directory directives should be mentioned in the suPHP documentation, don't you think so? But they aren't. The documentation only mentions "global contexts" and "<VirtualHost>" directives, but no Location and Directory directives. So either the documentation needs to be updated, or you have to tweak the sources.
Submitted by Dave (not registered) on Tue, 2009-01-06 18:09.

Great tutorial thanks! I used the latest version of suPHP 0.7.0, and this has those changes already in it, so I think you must have taken the right approach.

I also needed to install g++ to be able to compile the code (on Ubuntu).