User:Int 80h/files/php-fcgi
Appearance
< User:Int 80h | files
I retreived the script from some source on the internet. However it didn't work so well, so I changed it a bit, so it actually works.
php-fcgi
[edit]Obviously, this needs PHP compiled with FastCGI support. I suggest running this script manually, since it does not produce any pidfiles.
#!/bin/bash
## ABSOLUTE path to the PHP binary
PHPFCGI="/usr/bin/php5-cgi"
## tcp-port to bind on
FCGIPORT="9000"
## IP to bind on
FCGIADDR="127.0.0.1"
## number of PHP children to spawn
PHP_FCGI_CHILDREN=2
## number of request before php-process will be restarted
PHP_FCGI_MAX_REQUESTS=1000
## allowed environment variables sperated by spaces
ALLOWED_ENV="ORACLE_HOME PATH USER"
## if this script is run as root switch to the following user
USERID=www-data
################## no config below this line
if test x$PHP_FCGI_CHILDREN = x; then
PHP_FCGI_CHILDREN=5
fi
ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_CHILDREN"
ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS"
ALLOWED_ENV="$ALLOWED_ENV FCGI_WEB_SERVER_ADDRS"
if test x$UID = x0; then
EX="/bin/su -m -c \"$PHPFCGI -q -b $FCGIADDR:$FCGIPORT\" $USERID"
else
EX="$PHPFCGI -b $FCGIADDR:$FCGIPORT"
fi
echo $EX
# export vars used by php-cgi
export $ALLOWED_ENV
# start php-cgi into background
nohup sh -c "$EX" &> /dev/null &
nginx
[edit]I noticed, that PHP_FCGI_CHILDREN
should not be higher than 2, when using together with nginx.
This is a portion of nginx config file, that works in conjuctions with php-fcgi
. First there needs to be an upstream directive:
upstream phpfcgi {
server 127.0.0.1:9000;
}
Then, inside a "server" directive:
location ~ \.php$ {
fastcgi_pass phpfcgi;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
"fastcgi_params" comes with the nginx package, and lies inside /etc/nginx
when installed in Debian.