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:

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:

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:

7 Comment(s)

Add comment


From: Anonymous at: 2006-06-14 10:10:32

"suPHP integrates into Apache2 as a module. At the time of this writing it does work with Apache2 prior to version 2.2. Version 2.2 is not supported yet."

I think the paragraph should read:

"suPHP integrates into Apache2 as a module. At the time of this writing it does work with Apache2 prior to version 2.0. Version 2.2 is not supported yet."

From: Anonymous at: 2006-06-27 09:58:52

I created a similar guide "How to Compile suPHP+Apache2+PHP" at URL:

From: at: 2008-06-04 09:57:59
From: Anonymous at: 2006-06-14 19:57:33

So why would someone use this rather than suexec?

From: Anonymous at: 2006-06-12 21:30:20

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?

From: admin at: 2006-06-12 22:51:53

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.

From: Dave at: 2009-01-06 17:09:14

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).