lighttpd, web.py, spawning fcgi failed

The other day I was trying to deploy my newly written app on my VPS. It’s written based on the neat framework of web.py and I was planning to deploy it on lighttpd through fastcgi.

The process was not very smooth for me, as we always expect when trying out new things. The lighttpd server failed to start and by looking into the error log I found these lines:


2009-12-15 19:48:04: (server.c.1503) server stopped by UID = 0 PID = 25128 2009-12-15 19:48:30: (log.c.166) server started
2009-12-15 19:48:30: (mod_fastcgi.c.1104) the fastcgi-backend /var/www/code.py failed to start:
2009-12-15 19:48:30: (mod_fastcgi.c.1108) child exited with status 1 /var/www/code.py
2009-12-15 19:48:30: (mod_fastcgi.c.1111) If you're trying to run your app as a FastCGI backend, make sure you're using the FastCGI-enabled version.If this is PHP on Gentoo, add 'fastcgi' to the USE flags.
2009-12-15 19:48:30: (mod_fastcgi.c.1399) [ERROR]: spawning fcgi failed. 2009-12-15 19:48:30: (server.c.931) Configuration of plugins failed. Going down.

Finally I got it to work and here I’ll provide a check list in case someone else encounter the same problem.

Is code.py executable?

If not:

chmod 755 code.py

Also you need something like this on top of file:

#!/usr/bin/env python

Does helloword example work?

Use the example on web.py’s homepage (remember to add the line of python executable to the top of the file):


#!/usr/bin/env python
import web

urls = (
    '/(.*)', 'hello'
)
app = web.application(urls, globals())

class hello:
    def GET(self, name):
        if not name:
            name = 'world'
        return 'Hello, ' + name + '!'

if __name__ == "__main__":
    app.run()

Chances are this will work. Because this app is so simple and it doesn’t require many libraries.

check egg cache dir permission

Some libraries need to extract files to a directory (python egg cache). I used MySQL-python in my program and it might fail on that.
/sbin/.python-eggs/
Now change the GET method of hello class to:


try:
    import MySQLdb
except Exception, e:
    return str(e);
return 'hello'

If egg cache permission is the cause, you’ll see something like this when visiting the server:

Can’t extract file(s) to egg cache The following error occurred while trying to extract file(s) to the Python egg cache: [Errno 13] Permission denied: ‘/sbin/.python-eggs’ The Python egg cache directory is currently set to: /sbin/.python-eggs Perhaps your account does not have write access to this directory? You can change the cache directory by setting the PYTHON_EGG_CACHE environment variable to point to an accessible directory.

There are many ways to solve this problem, but I just changed the owner of this directory to the user who runs lighttpd (daemon in my case):

chown -R daemon.daemon /sbin/.python-eggs

Is lighttpd using the expected version of python?

My VPS is running CentOS 5.4 and I installed python 2.6 on it (CentOS ships with old 2.4 version). I have two python executables (/usr/local/bin/python and /usr/bin/python) on my $PATH, but python 2.6 has precedence on mine (root). At last it turned out that lighttpd was using the old python 2.4

So I changed the first line of code.py to be:

#!/usr/local/bin/python

Now lighttpd can start happily.

5 Responses to “lighttpd, web.py, spawning fcgi failed”

  1. lvckjeans Says:

    50. durée plus probable, sur la base de PUMA CHAUSSURES CPM, utilisez la méthode “nombre de pondérée”, le dernier seulement quatre ans pour terminer un plan NIKE TN de six ans, gain de temps atteint 33 %.

  2. bapejeans Says:

    50.immédiatement dans la vie politique en Yan’an suscite de fortes répercussions. Wang shiwei est SHOX RIVALRY un éminent représentant. Il est des artistes · politicien Lys sauvage “,”, scientifiques, * conscience ancien de LUNETTES CARRERA sensibilisation NIKE SKYLINE de la visionnaire, mais il ignore la transformation de l’artiste ; il a souligné que les artistes dans leur rôle important dans NIKE TN l’âme, mais les compagnies théâtrales exagérées et les politiciens, les écarts, ou même les deux, l’anti-Japanese * base décrit comme

  3. www.tnmax.com Says:

    2010 survetement adida addidas or versace watches baskets de foot ceinture ed hardy sweat burberry pull gucci lacoste manteau ceinture disel veste chile 62 maillot coupe du monde ceinture burberry ceinture prada maillot de la coupe du monde 2010 tee shirt lacoste femme air stab ensembles adidas air shoks maillot adidas bottes versace polo rayure lacoste manteau pull over lacoste mastercard adresse sac berbery crampon talaria adidas http://www.tnmax.com survetement nike tn pull over lacoste ceinture armani femme tee shirt playboy femme vapor talaria tee shirt gucci maillot 2010 manteau lacoste mercurial vapor talaria veste adidas chile 62 calecon dg adidas id sac berburry maillot de coupe uboat montres chaussures 25 montre u boot burberry ceinture lunettes burberry nike blaze survetements adidas manteau kappa adidas survetement adidas fendi t shirt

  4. www.Vaomart.Biz Says:

    Hello,Friends,Sells Nike TN Shoes, Adidas Wings Shoes, Franklin & Marshall Couvertures, Carreira Sunglasses, Adidas Chile 62 Jacket,at Cheap Price at http://www.vaomart.biz
    Accept Paypal
    MSN:Yaomart02@hotmail.com

  5. AshleyWoods Says:

    People deserve wealthy life time and loans or short term loan will make it better. Because freedom is based on money state.

Leave a Reply

Please copy the string qOTTQJ to the field below: