How To Set Up suPHP With PHP4 And PHP5 - Page 2
4 Install PHP4-CGI
I will first describe how to use suPHP with PHP4, then later in this tutorial how to use it with PHP5, and at the end how to use it with both installed at the same time.
As I mentioned earlier, suPHP needs PHP as CGI instead of the Apache module. Therefore we install the php4-cgi package like this:
apt-get install php4-cgi
5 Install suPHP
Next we download and unpack the suPHP sources. At the time of this writing the current version was 0.6.1:
Now we must edit src/apache2/mod_suphp.c because otherwise you'll get an error like this one:
when you put some suPHP directives in your Apache vhosts. Open the file, and in the lines 316 and 317 (the line numbers might differ if you use a suPHP version other than 0.6.1) you will find the string ACCESS_CONF. Replace it with RSRC_CONF | ACCESS_CONF so that the two lines look like this:
(If you prefer to edit the file on your Windows system, make sure you save it with Unix line breaks instead of Windows line breaks before you transfer the file back to your Linux system!)
Then we compile and install suPHP:
./configure --prefix=/usr --sysconfdir=/etc --with-apache-user=www-data --with-setid-mode=paranoid --with-apxs=/usr/bin/apxs2
Now we need to create the configuration file /etc/suphp.conf. We can do this by simply copying the template that comes with the sources:
cp /tmp/suphp-0.6.1/doc/suphp.conf-example /etc/suphp.conf
We must make a few changes to /etc/suphp.conf. Set the value of webserver_user to www-data (this is the username of the Apache user in Debian's default Apache package), and for x-httpd-php we must specify our php4-cgi binary which is /usr/bin/php4-cgi so the final file looks like this:
Then we have to add the suPHP module to the Apache configuration. Add the following line to /etc/apache2/httpd.conf:
Then restart Apache:
6 Apache Configuration
In this chapter I assume we have a web site www.example.com on the IP address 188.8.131.52 with the document root /var/www and the following vhost configuration:
In order to enable suPHP for the vhost www.example.com and let it run PHP scripts as the user testuser and the group test, we modify the vhost as follows:
AddHandler x-httpd-php refers to suPHP_AddHandler x-httpd-php which then refers to the x-httpd-php line in /etc/suphp.conf which means that scripts with the extensions .php, .php3, .php4, and .php5 are interpreted by /usr/bin/php4-cgi.
Now we create a simple phpinfo() script and access it in our browser:
Go to http://www.example.com/info.php in your browser, and you should see that you got PHP4 running:
If you encounter problems, please check /var/log/suphp.log and /var/log/apache2/error.log for errors. Most of the time you can fix them by changing the appropriate option in /etc/suphp.conf or by changing permissions of files/directories.