Skip to content

Instantly share code, notes, and snippets.

@yapus
Created April 26, 2013 21:57
Show Gist options
  • Save yapus/5470742 to your computer and use it in GitHub Desktop.
Save yapus/5470742 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Use this as a run script with daemontools or runit
## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/usr/bin/spawn-fcgi"
## ABSOLUTE path to the FastCGI application (php-cgi, dispatch.fcgi, ...)
FCGIPROGRAM="/usr/bin/php5-cgi"
## bind to unix socket
FCGISOCKET="/var/lib/php5/php_fastcgi.sock"
FCGISOCKETMODE=0600
# allowed environment variables separated by spaces
ALLOWED_ENV="PATH USER"
## if this script is run as root switch to the following user
USERID=php_fastcgi
GROUPID=webserv
SOCKUSERID=nginx
#CHROOT=/home/www/
#RAILS_ENV="production"
#export RAILS_ENV
PHP_FCGI_CHILDREN=32
################## no config below this line
exec 2>&1
if test x$PHP_FCGI_CHILDREN = x; then
PHP_FCGI_CHILDREN=4
fi
ALLOWED_ENV="$ALLOWED_ENV RAILS_ENV"
if test x$UID = x0; then
EX="$SPAWNFCGI -n -s $FCGISOCKET -M $FCGISOCKETMODE -u $USERID -g $GROUPID -U $SOCKUSERID -C $PHP_FCGI_CHILDREN -- $FCGIPROGRAM"
else
EX="$SPAWNFCGI -n -s $FCGISOCKET -M $FCGISOCKETMODE -C $PHP_FCGI_CHILDREN -- $FCGIPROGRAM"
fi
# 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
exec env - $E $EX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment