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:

cd /tmp
tar xvfz suphp-0.6.1.tar.gz
cd suphp-0.6.1

Now we must edit src/apache2/mod_suphp.c because otherwise you'll get an error like this one:

Forcing reload of web server: Apache2Syntax error on line 49 of /etc/apache2/sites-enabled/000-default:
suPHP_AddHandler not allowed here

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:

vi src/apache2/mod_suphp.c
    AP_INIT_ITERATE("suPHP_AddHandler", suphp_handle_cmd_add_handler, NULL, RSRC_CONF | ACCESS_CONF, "Tells mod_suphp to handle these MIME-types"),
AP_INIT_ITERATE("suPHP_RemoveHandler", suphp_handle_cmd_remove_handler, NULL, RSRC_CONF | ACCESS_CONF, "Tells mod_suphp not to handle these MIME-types"),

(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
make install

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:

vi /etc/suphp.conf
;Path to logfile


;User Apache is running as

;Path all scripts have to be in

;Path to chroot() to before executing script

; Security options

;Check wheter script is within DOCUMENT_ROOT

;Send minor error messages to browser

;PATH environment variable

;Umask to set, specify in octal notation

; Minimum UID

; Minimum GID

;Handler for php-scripts

;Handler for CGI-scripts

Then we have to add the suPHP module to the Apache configuration. Add the following line to /etc/apache2/httpd.conf:

vi /etc/apache2/httpd.conf
LoadModule suphp_module       /usr/lib/apache2/modules/

Then restart Apache:

/etc/init.d/apache2 restart

6 Apache Configuration

In this chapter I assume we have a web site on the IP address with the document root /var/www and the following vhost configuration:

ServerAdmin [email protected]
DocumentRoot /var/www

In order to enable suPHP for the vhost and let it run PHP scripts as the user testuser and the group test, we modify the vhost as follows:

ServerAdmin [email protected]
DocumentRoot /var/www

suPHP_Engine on
suPHP_UserGroup testuser test
AddHandler x-httpd-php .php .php3 .php4 .php5
suPHP_AddHandler x-httpd-php

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.

Restart Apache:

/etc/init.d/apache2 restart

Now we create a simple phpinfo() script and access it in our browser:

vi /var/www/info.php

Go to 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.

Share this page:

0 Comment(s)