spawn-fcgi on Archlinux

19 April 2009 tags:

In the past I was a user of the lighttpd web server. This worked fine and I had little problems with it. I have since moved to Nginx for all my web hosting requirements and have been more than happy with the increased speed and smaller memory footprint (your mileage may vary!). One thing that I have missed, however, was the fantastic little fast-cgi spawner ‘spawn-fcgi’ that was bundled with Lighttpd.

It turns out that the spawn-fcgi project has been split off from lighttpd and is its own entity hosted at http://redmine.lighttpd.net/projects/spawn-fcgi. This means you can use it easily without having to compile ‘Lighty’ and then extract spawn-fcgi. It can make running a PHP service really quite easy. Try it.

I just recently updated the spawn-fcgi package in the Archlinux AUR repository to version 1.6.2 which fixes some bugs and adds some new features, notably IPv6. It can be used to run all manner of things using the fast-cgi method but more often than not it is used for PHP. Here is a possible startup script for Archlinux that you could place in /etc/rc.d/php5-fcgi

#!/bin/bash

# general config
. /etc/rc.conf
. /etc/rc.d/functions

case "$1" in
  start)
    check_config
    stat_busy "Starting PHP5"
    if [ -s /var/run/php5-fcgi.pid ]; then
      stat_fail
      # probably ;)
      stat_busy "PHP5 is already running"
      stat_die
    fi
    /usr/bin/spawn-fcgi -s /tmp/php5-cgi.sock -P /var/run/php5-fcgi.pid -u nginx -f /usr/bin/php-cgi &>/dev/null
    if [ $? -ne 0 ]; then
      stat_fail
    else
      add_daemon php5-fcgi
      stat_done
    fi
    ;;
  stop)
    stat_busy "Stopping PHP5"
    kill -QUIT `cat /var/run/php5-fcgi.pid` &>/dev/null
    if [ $? -ne 0 ]; then
      stat_fail
    else
      rm_daemon php5-fcgi
      stat_done
    fi
    ;;
  restart)
    $0 stop
    sleep 1
    $0 start
    ;;
  reload)
    check_config
    if [ -s /var/run/php5-fcgi.pid ]; then
      status "Reloading PHP5 Configuration" kill -HUP `cat /var/run/php5-fcgi.pid`
    fi
    ;;
  check)
    check_config
    ;;
  *)
    echo "usage: $0 {start|stop|restart|reload|check}"  
esac

Possibly Similar Pages


Comments on this post

blog comments powered by Disqus
loading