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?
chmod 755 code.py
Also you need something like this on top of file:
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.
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:
Now lighttpd can start happily.