HomePage » WebServer » PHP » PHPFastCGI


Apache config:
# Without fastcgi
AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php.fcgi
DirectoryIndex index.php index.html


# with fastcgi
FastCgiIpcDir /tmp

AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php.fcgi
DirectoryIndex index.php index.html

<Location /cgi-bin/php.fcgi>
	SetHandler fastcgi-script
	Options +ExecCGI
</Location>


With the fastcgi config, php-cgi processes are now under httpd:
ps jaxf
...
	1 25864 25864 25864 ?           -1 Ss       0   0:00 /usr/sbin/httpd
25864 25865 25864 25864 ?           -1 S       48   0:00  \_ /usr/sbin/fcgi-
25865 25882 25882 25882 ?           -1 Ss      48   0:00  |   \_ /usr/local/bin/php-cgi
25882 25883 25882 25882 ?           -1 S       48   0:00  |       \_ /usr/local/bin/php-cgi
25882 25884 25882 25882 ?           -1 S       48   0:00  |       \_ /usr/local/bin/php-cgi
25882 25885 25882 25882 ?           -1 S       48   0:00  |       \_ /usr/local/bin/php-cgi
25882 25886 25882 25882 ?           -1 S       48   0:00  |       \_ /usr/local/bin/php-cgi
25882 25887 25882 25882 ?           -1 S       48   0:00  |       \_ /usr/local/bin/php-cgi
25882 25888 25882 25882 ?           -1 S       48   0:00  |       \_ /usr/local/bin/php-cgi
25882 25889 25882 25882 ?           -1 S       48   0:00  |       \_ /usr/local/bin/php-cgi
25882 25890 25882 25882 ?           -1 S       48   0:00  |       \_ /usr/local/bin/php-cgi
25882 25891 25882 25882 ?           -1 S       48   0:00  |       \_ /usr/local/bin/php-cgi
25882 25892 25882 25882 ?           -1 S       48   0:00  |       \_ /usr/local/bin/php-cgi


Wrapper script php.fcgi:
#!/bin/bash
# Shell Script To Run PHP5 using mod_fastcgi under Apache 2.x
# Tested under Red Hat Enterprise Linux / CentOS 5.x
### Set PATH ###
PHP_CGI=/usr/local/bin/php-cgi
PHP_FCGI_CHILDREN=10
PHP_FCGI_MAX_REQUESTS=1000
### no editing below ###
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec $PHP_CGI


fcgid

fcgid needs to be installed separately from apache: http://httpd.apache.org/mod_fcgid/

Apache config:
FcgidMaxProcesses 100
FcgidIPCDir /tmp
FcgidPassHeader HTTP_AUTHORIZATION
FcgidIdleTimeout 620

<Location />
	   AddHandler fcgid-script .php
	   Options +ExecCGI
	   FcgidWrapper /var/www/cgi-bin/php.fcgi .php
	   Order allow,deny
	   Allow from all
</Location>


The wrapper script is the same as the one used on mod_fastcgi

spawn-fcgi

haven't tried this myself on apache:

Spawn-fcgi process
/usr/bin/spawn-fcgi -f /usr/bin/php-cgi -s /tmp/php.socket -u apache -g apache


Apache config
<VirtualHost nixcraft.com:80>
	ServerAdmin webmaster@nixcraft.com
	DocumentRoot /webroot/http
	ServerName nixcraft.com
	ErrorLog logs/nixcraft.com-error_log
	CustomLog logs/nixcraft.com-access_log common
	AddHandler php5-fastcgi .php
	FastCgiExternalServer /webroot/http -host 192.168.1.10:9000
#    FastCgiExternalServer /webroot/http -socket /tmp/php.socket
</VirtualHost>

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki