This page summaries a working setup of PHP on Apache, using fcgid and suexec. It has been tested with Apache 2.2 on a Debian Linux system.
You need to adapt the following values to your own setup:
user_account:the user account under which your PHP scripts will run.
user_group:the group that will be used to run your PHP scripts.
www-data:the user account used by Apache.
php_site:the directory under which your web site will be installed.
Apache 2 setup
suexec Apache modules. If you’re using a Debian, this
can be done with the following commands:
a2enmod suexec a2enmod fcgid
Modifiy your virtuals hosts as follows:
<VirtualHost *> DocumentRoot /var/www/user_account/php_site [...] Options None SuexecUserGroup user_account user_group <Directory /var/www/user_account/php_site> # The PHP scripts in this directory # are run through the php-cgi script. AddHandler fcgid-script .php FCGIWrapper /var/www/user_account/php-cgi .php Options ExecCGI </Directory> # We run a single PHP FastCGI server # which will launch as many children # as necessary. DefaultMaxClassProcessCount 1 DefaultMinClassProcessCount 1 </VirtualHost>
You now need to check that you Apache is correctly set up:
Directory structure creation
Unless you use the
mod_userdir Apache module, your will need to work in a
First, create the directories that will contain your site:
mkdir -p /var/www/user_account/php_site
Then copy your files in the
Place the following script in a file called “php-cgi”, in the
#!/bin/sh export PHP_FCGI_CHILDREN=4 export PHP_FCGI_MAX_REQUESTS=500 exec /usr/bin/php-cgi $@
When this script is started by Apache, it will automatically be replaced
php-cgi process. This process will start 4 chilren, to process
the incoming requests. Once a child will have processed 500 requests, it
will automatically shutdown and be restarted by the initial process.
This feature is here to prevent a possible memory leak.
Your should adapt the number of children (
PHP_FCGI_CHILDREN) to suit
your needs. A lower value (e.g. 4) will be less demanding on your
server. A higher value (e.g. 8) will enable your server to handle more
Apply the following permissions:
# User account directory chown user_account:user_group /var/www/user_account chmod u=rwx,g=rx,o=rx /var/www/user_account # Wrapper script chown user_account:user_group /var/www/user_account/php-cgi chmod u=rwx,ug= /var/www/user_account/php-cgi # Site chown user_account:www-data /var/www/user_account/php_site chmod -R u=rwX,g=rX,o= /var/www/user_account/php_site
Everything should be OK now, you just need to restart Apache:
- The SUEXEC documentation of the Apache project.
- The README.FastCGI file, which is included in the PHP sources.
(cgi-fcgi)” in its output.
License : CC-BY