Running PHP with fcgid

Why ?

Benefits

On what conditions not to run php on fcgid

Quick How to

Follow ALL steps, or something will be missing in the end.

  1. Unload mod_php by commenting out the LoadModule directive from your configuration.

  2. Load the mod_fcgid module with the LoadModule directive.

  3. Install PHP as CGI using your package manager.
  4. Write a small wrapper, such as this : /usr/local/bin/php-wrapper


#!/bin/sh

# Set desired PHP_FCGI_* environment variables.

# Example:

# PHP FastCGI processes exit after 1000 requests by default.

PHP_FCGI_MAX_REQUESTS=1000

export PHP_FCGI_MAX_REQUESTS

# Replace with the path to your FastCGI-enabled PHP executable

exec /usr/lib/cgi-bin/php5


Make sure it is readable and executable by the apache user/group.

  1. Configuration - httpd.conf

LoadModule fcgid_module <path to modules>/mod_fcgid.so

AddHandler fcgid-script .php

FcgidWrapper /usr/local/bin/php-wrapper .php

  1. Replace prefork MPM with a threaded MPM, such as worker. On 2.4, you can now change the active mpm by loading the appropriate module.

FAQ / It doesn't work

Don't panic. Check apache httpd error log.

PHP files are downloaded, not interpreted

If you have a handler already set for PHP, it may be conflicting. So you can try something like : "grep -ri handler /etc/httpd | grep php" depending on the result, you may need to comment out some config you are having.

Further options

You should read http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#upgrade

php-fcgid (last edited 2016-11-13 17:20:26 by thumbs)