Skip to content

Instantly share code, notes, and snippets.

@white-gecko
Created November 5, 2012 20:18
Show Gist options
  • Save white-gecko/4020109 to your computer and use it in GitHub Desktop.
Save white-gecko/4020109 to your computer and use it in GitHub Desktop.
The init script to start php-fastcgi to use it with nginx
To use nginx with fastcgi you need following packages:
apt-get install nginx php5-cli php5-cgi spawn-fcgi psmisc
Create a symlink link /etc/init.d/php-fastcgi pointing to ./etc_init.d_php-fastcgi
and a link /usr/bin/php-fastcgi pointing to ./usr_bin_php-fastcgi
Note: Both files need to be executable (chmod +x <file>)
To enable the init script run
sudo update-rc.d php-fastcgi defaults
and
sudo update-rc.d php-fastcgi enable
Further information can be found at:
http://library.linode.com/web-servers/nginx/php-fastcgi/ubuntu-10.04-lucid
#!/bin/bash
#
# Initscript to start fast cgi
# from http://library.linode.com/web-servers/nginx/php-fastcgi/ubuntu-10.04-lucid
#
### BEGIN INIT INFO
# Provides: php-fastcgi
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop script für php fast cgi
# Description: This file starts the php fast cgi socket
### END INIT INFO
PHP_SCRIPT=/usr/bin/php-fastcgi
FASTCGI_USER=www-data
FASTCGI_GROUP=www-data
PID_DIR=/var/run/php-fastcgi
PID_FILE=/var/run/php-fastcgi/php-fastcgi.pid
RET_VAL=0
case "$1" in
start)
if [[ ! -d $PID_DIR ]]
then
mkdir $PID_DIR
chown $FASTCGI_USER:$FASTCGI_GROUP $PID_DIR
chmod 0770 $PID_DIR
fi
if [[ -r $PID_FILE ]]
then
echo "php-fastcgi already running with PID `cat $PID_FILE`"
RET_VAL=1
else
$PHP_SCRIPT
RET_VAL=$?
fi
;;
stop)
if [[ -r $PID_FILE ]]
then
kill `cat $PID_FILE`
rm $PID_FILE
RET_VAL=$?
else
echo "Could not find PID file $PID_FILE"
RET_VAL=1
fi
;;
restart)
if [[ -r $PID_FILE ]]
then
kill `cat $PID_FILE`
rm $PID_FILE
RET_VAL=$?
else
echo "Could not find PID file $PID_FILE"
fi
$PHP_SCRIPT
RET_VAL=$?
;;
status)
if [[ -r $PID_FILE ]]
then
echo "php-fastcgi running with PID `cat $PID_FILE`"
RET_VAL=$?
else
echo "Could not find PID file $PID_FILE, php-fastcgi does not appear to be running"
fi
;;
*)
echo "Usage: php-fastcgi {start|stop|restart|status}"
RET_VAL=1
;;
esac
exit $RET_VAL
#!/bin/bash
FASTCGI_USER=www-data
FASTCGI_GROUP=www-data
SOCKET=/var/run/php-fastcgi/php-fastcgi.socket
PIDFILE=/var/run/php-fastcgi/php-fastcgi.pid
CHILDREN=6
PHP5=/usr/bin/php5-cgi
/usr/bin/spawn-fcgi -s $SOCKET -P $PIDFILE -C $CHILDREN -u $FASTCGI_USER -g $FASTCGI_GROUP -f $PHP5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment