How To Set Up suPHP With PHP4 And PHP5 - Page 2
On this page
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
wget http://www.suphp.org/download/suphp-0.6.1.tar.gz
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: |
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"), |
(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
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
[global] |
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/mod_suphp.so |
Then restart Apache:
/etc/init.d/apache2 restart
6 Apache Configuration
In this chapter I assume we have a web site www.example.com on the IP address 1.2.3.4 with the document root /var/www and the following vhost configuration:
<VirtualHost 1.2.3.4> |
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:
<VirtualHost 1.2.3.4> |
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
<?php |
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.