How To Set Up suPHP With PHP4 And PHP5

Version 1.0
Author: Falko Timme
Last edited 06/10/2006

This tutorial shows how to install and use suPHP with PHP4 and PHP5. suPHP is a tool for executing PHP scripts with the permissions of their owners instead of the Apache user. With the help of suPHP you can also have PHP4 and PHP5 installed at the same time which I will describe at the end of this article.

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.

This tutorial was written with the help of a Debian Sarge system, but as I compile suPHP from the sources here instead of installing some distribution specific suPHP packages, most of the steps should apply also to other distributions.

I want to say first that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

1 Install Apache

If you don't already have Apache2 installed, install it like this:

apt-get install apache2 apache2-doc

2 Disable the Apache PHP Module

If you already had Apache2 installed with PHP4 as a module, you must disable that module now because suPHP uses the CGI version of PHP to work (if you don't know if you have PHP4 installed as module, you can also run this command - it doesn't hurt):

a2dismod php4

Do the same for PHP5 if you have the PHP5 module installed (the official Debian Sarge repositories don't have PHP5 packages, however it's possible that you installed third-party PHP5 packages like those from

a2dismod php5

Then restart Apache:

/etc/init.d/apache2 restart

3 Install apxs

From suPHP's installation manual:

The easiest way to install mod_suphp is to compile it as a dynamically loadable module (DSO). If your Apache was compiled with DSO support and "apxs" is either in your path or you specified the path to it when running "configure", mod_suphp will automatically be compiled when doing "make" and installed to your Apache server (when doing "make install").

We want to install suPHP as a DSO, therefore we must install apxs (on Debian Sarge it's apxs2). It is provided by the apache2-prefork-dev package which we install now:

apt-get install apache2-prefork-dev

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