What all should i do to use mod_fcgid instead of mod_php on ubuntu and centos. what are the main benefits and difference's between two
-
so, what is it you want to replace? mod_cgi or mod_php? note that the three are different things that call different kinds of 'backend' with different protocols. – Javier Dec 22 '10 at 14:21
-
be aware that mod_fcgid actually has to read an entire request in before handing it to the fastcgi script - this could have significant performance issues if you are expecting large request bodies such as file attachments. – PP. Dec 23 '10 at 11:41
3 Answers
On my shared hosting platform I use FastCGI to run PHP through rather than calling it directly. They run PHP via CGI by default rather than as a module so for me it was just a matter of adding the following to my .htaccess
file:
AddHandler application/myphp .php
Action application/myphp /cgi-bin/myphp.fcgi
Next I had to create the myphp.fcgi
script in my cgi-bin directory containing:
#!/bin/sh
# This ensures PHP doesn't try to run it's own
# process manager.
export PHP_FCGI_CHILDREN=0
# Replace this shell image with a PHP
# image.
exec /path/to/php -c /path/to/my/php.ini
This runs flawlessly for me and my hosting environment is running within a cluster of almost a dozen servers behind a hardware load balancer.
![](../../users/profiles/9052.webp)
- 11,241
- 2
- 27
- 40
mod_php:
- a bit faster, than mod_fcgid
- runs under httpd process
- have access to apache api ( de.php.net/manual/en/ref.apache.php )
- bad for shared hosting, since all domains run under the same user
mod_fcgid:
- scripts runs under the user you want (good for shared hosting)
- enhanced security
- can run more than just php
- you can rund multiple php versions i.e. php4, php5, php5.1, php5.2, php 5.3
![](../../users/profiles/64660.webp)
- 1,451
- 4
- 19
- 27
-
What I only miss here is how you can use fastcgi instead of mod php, so how you switch from mod php to fastcgi, which I thought was part of the question as well. – rhand Feb 27 '15 at 06:48
-
Many sites rely very much on apache api features and will not work without it. – sekrett Apr 22 '16 at 08:16
cgi = each request starts a process and get's results back to client fcgi = application (Ruby/Django for example) or interpreter (PHP) stays running and webserver forwards requests and gets responses from it.
FastCGI is almost always faster (for stuff that supports it), however some very ancient stuff (nagios for example) needs cgi. Only real advantage of cgi is that where there is no traffic scripts cgi application does not use memory, but usually webserver is intelligent enough to shut down FastCGI app that's not used for some time, so that's not a real advantage
![](../../users/profiles/64488.webp)
- 392
- 1
- 3