Skip to content

Instantly share code, notes, and snippets.

@christianchristensen
Created July 18, 2012 15:37
Show Gist options
  • Save christianchristensen/3136985 to your computer and use it in GitHub Desktop.
Save christianchristensen/3136985 to your computer and use it in GitHub Desktop.
PHP CGI start script
#!/bin/bash
BIND=127.0.0.1:9009
USER=www-data
PHP_FCGI_CHILDREN=3
PHP_FCGI_MAX_REQUESTS=10
PHP_VERSION=`cat ~/.phpenv/version`
PHP_CGI="/home/chris/.phpenv/versions/$PHP_VERSION/bin/php-cgi"
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS="- USER=$USER PATH=/home/chris/.phpenv/versions/$PHP_VERSION/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
RETVAL=0
start() {
echo -n "Starting PHP FastCGI: "
start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS
RETVAL=$?
echo "$PHP_CGI_NAME."
}
stop() {
echo -n "Stopping PHP FastCGI: "
killall -q -w -u $USER $PHP_CGI
RETVAL=$?
echo "$PHP_CGI_NAME."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: php-fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
@xeoncross
Copy link

You should be using apt-get install php5-fpm - manual scripts like this are prone to failure.

@christianchristensen
Copy link
Author

@xeoncross Fair point! Can you point to the the source conf. file that uses, particularly so I can see how the service is setup prior to installation?

@xeoncross
Copy link

No, I cannot. However it has it's own configuration file you can see after installation that you can customize to your liking. I used to use a custom php-cgi wrapper like this and then I installed php5-fpm (at the same time) and moved everything over and then removed my /etc/init./php-fastcgi script. Actually, I think I have php-cgi still installed - I should remove it since it's not needed for anything.

$ sudo apt-get install php-cli php5-fpm

Is all that's needed for systems running a FastCGI daemon. After install, checkout /etc/php5/ to see the new configs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment