#!/bin/bash # Description: PHP-FastCgi start script from http://blog.kovyrin.net/2006/05/30/nginx-php-fastcgi-howto/ # # Author: Alexey Kovyrin http://blog.kovyrin.net # Comments by: Geoffrey Grosenbach http://topfunky.com # # This script is started once and receives PHP requests from Nginx for # all apps. The Nginx config passes the full path to the script being requested, so # only one fastcgi runner is needed for all apps, virtual hosts, etc. # # See also the init.d script for starting this on boot. # # To install PHP, I had to also compile the following: # # * http://www.gnu.org/software/m4/ # * http://flex.sourceforge.net/ # * http://php.net/ with './configure --prefix=/usr/local --enable-fastcgi' ## ABSOLUTE path to the PHP binary PHPFCGI="/usr/local/bin/php" ## 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=5 ## number of request before php-process will be restarted PHP_FCGI_MAX_REQUESTS=1000 # allowed environment variables sperated by spaces ALLOWED_ENV="PATH USER" ## if this script is run as root switch to the following user USERID=deploy ################## 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 # copy the allowed environment variables E= for i in $ALLOWED_ENV; do E="$E $i=${!i}" done # clean environment and set up a new one nohup env - $E sh -c "$EX" &> /dev/null &