Skip to content

Instantly share code, notes, and snippets.

@stran12
Created November 26, 2011 00:43
Show Gist options
  • Save stran12/1394757 to your computer and use it in GitHub Desktop.
Save stran12/1394757 to your computer and use it in GitHub Desktop.
Step-by-step installation of cGit with Nginx

How to install cGit on Nginx (Ubuntu server)

Step-by-step installtion of cGit on nginx without funky rewrite rules.

Pre-requisites

This is for

sudo aptitude install build-essential
                      autoconf
                      automake
                      libtool
                      libfcgi-dev
                      spawn-fcgi
                      fcgiwrap

Now lets install fcgiwrap. Alternatively, you can

git clone https://github.com/gnosek/fcgiwrap.git
cd fcgiwrap/
autoreconf -i
./configure
make
sudo make install
cp fcgiwrap /usr/bin/.

Then, I pasted this perl script into /usr/bin/spawn-fcgi which will create a socket to pass .cgi to it

cat > /usr/bin/spawn-fcgi
#!/usr/bin/perl

use strict;
use warnings FATAL => qw( all );

use IO::Socket::UNIX;

my $bin_path = '/usr/bin/fcgiwrap';
my $socket_path = $ARGV[0] || '/tmp/cgi.sock';
my $num_children = $ARGV[1] || 1;

close STDIN;

unlink $socket_path;
my $socket = IO::Socket::UNIX->new(
    Local => $socket_path,
    Listen => 100,
);

die "Cannot create socket at $socket_path: $!\n" unless $socket;

for (1 .. $num_children) {
    my $pid = fork;
    die "Cannot fork: $!" unless defined $pid;
    next if $pid;

    exec $bin_path;
    die "Failed to exec $bin_path: $!\n";
}

Then make sure to give it executable permissions

chmod +x /usr/bin/spawn-fcgi

The following script will be use to automate the respawning of FastCGI(fcgi) socket

cat > /etc/init.d/spawn-fcgi
#!/bin/bash
C_SCRIPT=/usr/bin/spawn-fcgi
USER=www-data
GROUP=www-data
RETVAL=0
case "$1" in
        start)
                echo "Starting fastcgi"
                sudo -u $USER $C_SCRIPT
                chown $USER:$GROUP /tmp/cgi.sock
                RETVAL=$?
  ;;
        stop)
                echo "Stopping fastcgi"
                killall -9 fcgiwrap
                RETVAL=$?
  ;;
        restart)
                echo "Restarting fastcgi"
                killall -9 fcgiwrap
                $sudo -u $USER $C_SCRIPT
                RETVAL=$?
  ;;
        *)
                echo "Usage: $0 {start|stop|restart}"
                exit 1
  ;;
esac
exit $RETVAL

Again, make that executable and start it up!

chmod +x /etc/init.d/spawn-fcgi
sudo /etc/init.d/spawn-fcgi start

References

Copy link

ghost commented Jun 27, 2016

Nice manual, I used it, it works. Thank you.

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