Shouldn't really matter which distribution you're running but here is the setup I'm using for my CentOS server but should be able to translate easy enough for whichever you're using. You'll want to use the Worker MPM for Apache2 vs the Prefork MPM for the best results.
Assumption is that you've already installed mod_fastcgi either by distribution packaging or from source code. Once you have mod_fastcgi installed then you want to ensure it's configured to be loaded via Apache2, I did so in /etc/httpd/conf.d/mod_fastcgi.conf containing:
LoadModule fastcgi_module modules/mod_fastcgi.so
Next I created another file as /etc/httpd/conf.d/whatever.conf (Name whatever to anything you want really, for me it was wordpress.conf):
This then means in your cgi-bin directory (for me that is /var/www/cgi-bin/ I need to create the php.fcgi script and chmod 755 it. Mine contains:
#!/bin/bash
### Set PATH ###
PHP_CGI=/usr/bin/php-cgi
PHP_FCGI_CHILDREN=0
PHP_FCGI_MAX_REQUESTS=1000
### no editing below ###
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec $PHP_CGI
Of course update the PHP_CGI path if it's different for your system. You can also change the PHP_FCGI_CHILDREN value, I've seen some recommend setting it to 4 but I've left it at 0 and had good performance.
At this point you should be able to give Apache2 a restart to re-read the configurations and if you setup a simple phpinfo() page to query you should see it saying the ServerAPI setting stating CGI/FastCGI.
Shouldn't really matter which distribution you're running but here is the setup I'm using for my CentOS server but should be able to translate easy enough for whichever you're using. You'll want to use the Worker MPM for Apache2 vs the Prefork MPM for the best results.
Assumption is that you've already installed mod_fastcgi either by distribution packaging or from source code. Once you have mod_fastcgi installed then you want to ensure it's configured to be loaded via Apache2, I did so in
/etc/httpd/conf.d/mod_fastcgi.conf
containing:Next I created another file as
/etc/httpd/conf.d/
whatever.conf
(Name whatever to anything you want really, for me it waswordpress.conf
):This then means in your
cgi-bin
directory (for me that is/var/www/cgi-bin/
I need to create thephp.fcgi
script andchmod 755
it. Mine contains:Of course update the PHP_CGI path if it's different for your system. You can also change the PHP_FCGI_CHILDREN value, I've seen some recommend setting it to 4 but I've left it at 0 and had good performance.
At this point you should be able to give Apache2 a restart to re-read the configurations and if you setup a simple phpinfo() page to query you should see it saying the
ServerAPI
setting statingCGI/FastCGI
.What Distro?
Here's a tutorial for moving from mod_php to mod_fcgid on Ubuntu: