also about fastcgi, etc

Basic info

wiki page

http://wiki.codemongers.com/Main

Build Nginx

./configure --user=www-data --group=www-data --prefix=/usr/local/nginx --with-http_stub_status_module

Reload config file

test syntax of config file:

/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

reload config

kill -HUP `cat /usr/local/nginx/logs/nginx.pid`

Show Nginx status

When building nginx, need to specify the http_stub_status_module which is OFF by default.

        location /status {
            stub_status on;
            access_log off;
        }

The output of /status page looks like this:

Active connections: 1
server accepts handled requests
 2977 2977 3165
Reading: 0 Writing: 1 Waiting: 0

install PHP and fpm

download php 5.2.6 and fpm 0.5.8 patch for php 5.2.6.

apply the patch

patch -d php-5.2.6 -p1 < php-5.2.6-fpm-0.5.8.diff

install php

./configure \
--prefix=/usr/local/php-fpm/ \
--with-pgsql \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-discard-path \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fastcgi \
--enable-fpm \
--enable-force-cgi-redirect \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl

Document for php-fpm in Chinese http://syre.blogbus.com/logs/20092011.html

A guide of nginx+php in Chinese http://blog.s135.com/read.php?366

Chinese wiki http://www.nginx.cn/

serve PHP pages

The config file php-fpm.conf for fpm is at $PREFIX/etc, it's in XML.

The interface and port that the fastcgi php processes listen can be found in the config file. Also number of processes, access control, log/pid file

To start fpm at boot, see Linux

Run fpm from command line:

/usr/local/php-fpm/sbin/php-fpm start

Here is a segment of the nginx.conf file: Serving php from two dirs: /alt and /php:

        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9020;
            include /usr/local/nginx/conf/fastcgi_params.default;
            fastcgi_param  SCRIPT_FILENAME /var/www/$fastcgi_script_name;
        }
        location /alt {
            root /var/www/;
            index index.php index.html;
        }
        location /php {
            root /var/www/;
            index index.php index.html;
        }

Without the correct "SCRIPT_FILENAME", you will get "no input file specified" from the browser.

With this setup, Ganglia (the web interface) and phpPgAdmin both run fine.

P.S. about PATH_INFO, SCRIPT_NAME, etc: http://hoohoo.ncsa.uiuc.edu/cgi/env.html

php.ini

run php --ini will show where php searches for .ini file.

Run MoinMoin wiki with Nginx

The segment from nginx.conf

        location /moin_static171 {
            alias /usr/local/share/moin/htdocs/;
        }
        location /rpcwiki {
            include /usr/local/nginx/conf/fastcgi_params.default;
            if ($uri ~ ^/rpcwiki(.*)?) {
                set $wiki_url $1;
            }
            fastcgi_param PATH_INFO $wiki_url;
            fastcgi_param SCRIPT_NAME /rpcwiki;
            fastcgi_pass 127.0.0.1:9010;
        }

To start the MoinMoin fastcgi process, copy moin.fcg from $PREFIX/server/ to where the wiki instance is.

Since in this setup, moin.fcg runs as an external process, need to listen to certain port, add this in the function class Config(FastCgiConfig):

port = 9100

There is a problem with Nginx: web server should decode path_info and pass it on to CGI. But nginx doesn't (as for v0.6.32).

There are some discussion http://www.ruby-forum.com/topic/139942

In this case, when you create WikiNames that contains spaces, e.g. 'Data Production', MoinMoin will look for the page 'Data%20Production'. This is all nginx's fault but can be fixed by modify MoinMoin. Find /usr/local/lib/python2.5/site-packages/MoinMoin/request/__init__.py or whatever your MoinMoin code is, in the function fixURI(), add this

        if 'nginx' in server_software:
            import urlparse
            scriptAndPath = urlparse.urlparse(self.request_uri)[2]
            path = scriptAndPath.replace(self.script_name, '', 1)
            self.path_info = wikiutil.url_unquote(path, want_unicode=False)

More about MoinMoin and FastCGI: http://moinmo.in/HelpOnInstalling/FastCgi, it includes an example start-up script for Mac OS X

MoinMoin startup script

#!/bin/sh
set -e

USER=www-data
PIDFILE=/usr/local/share/moin/rpcwiki/moin.pid
PYEXE=/usr/local/share/moin/rpcwiki/moin.fcg

start_moinmoin () {
    su $USER -c "$PYEXE > /dev/null 2>&1 &"
}

stop_moinmoin () {
        if [ -e "$PIDFILE" ]; then
                kill `cat "$PIDFILE"`
        fi
        rm -f "$PIDFILE"
}

case "$1" in
        start)
                start_moinmoin
        ;;
        stop)
                stop_moinmoin
        ;;
        restart)
                stop_moinmoin
                start_moinmoin
        ;;
        *)
                echo "Usage: `basename $0` {start|stop|restart}"
                exit 64
        ;;
esac

And moin.cfg needs to be modified, add the following so it writes out its own pid file

fpid = file('/usr/local/share/moin/rpcwiki/moin.pid', 'w')
print >>fpid, os.getpid()
fpid.close()

Catalyst and FastCGI

http://search.cpan.org/~mramberg/Catalyst-Runtime-5.7014/lib/Catalyst/Engine/FastCGI.pm

start the server

./script/rpcfact_fastcgi.pl -l 127.0.0.1:9000 -p /var/www/RPCFact/pid -n 5 -d

To kill the FastCGI processes, send SIGTERM, see http://search.cpan.org/~gbjk/FCGI-ProcManager-0.18/ProcManager.pm

kill -TERM `cat /var/www/RPCFact/pid`

To get Catalyst working with nginx, need to modify the PATH_INFO setting:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

# modified
fastcgi_param  PATH_INFO          $fastcgi_script_name;

fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

The segment in nginx.conf is

        location / {
            fastcgi_pass 127.0.0.1:9000;
            include /usr/local/nginx/conf/fastcgi_params;
        }