Differences between revisions 7 and 8
Revision 7 as of 2013-06-02 12:36:55
Size: 1981
Editor: gryzor
Comment:
Revision 8 as of 2013-06-18 18:55:04
Size: 2328
Editor: gryzor
Comment:
Deletions are marked like this. Additions are marked like this.
Line 55: Line 55:
== FAQ / It doesn't work ==
Don't panic. Check apache 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.

Running PHP with fcgid

Why ?

  • Because mod_php forces you to load prefork MPM, which is inefficient.
  • Because mod_php will be loaded into httpd's memory even when serving static pages
  • Most distributions shipping in 2013 provide precompiled packages that let you run php with fcgid. This is just a matter of configuration.
  • mod_fcgid is an official Apache module, available at http://httpd.apache.org/mod_fcgid/

Benefits

  • Huge performance boost, both in CPU and memory consumption
  • PHP runs into a separated process

On what conditions not to run php on fcgid

  • If you run httpd 2.4, you should consider PHP-FPM

Quick How to

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

  1. Get rid of mod_php. You need to comment out the "LoadModule php5_module" from your configuration.

On debian, just run "apt-get remove libapache2-mod-php5"

  1. Install mod_fcgid

On debian, "apt-get install libapache2-mod-fcgid"

  1. Install PHP as CGI

On debian, "apt-get install php5-cgi"

  1. 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 /usr/lib/apache2/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 debian, just run "apt-get install apache2-mpm-worker"

FAQ / It doesn't work

Don't panic. Check apache 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 2013-06-18 18:55:04 by gryzor)