LIGHTTPD, web.py, spawning fcgi failed
web.py-based programs are very simple to develop, but I didn't expect to have a lot of trouble deploying on the server. I use the Web server is LIGHTTPD, does not start normally, look at the error log, found the following 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 started2009-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.py2009-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.
After a lot of trouble, the problem has finally been solved--not really just a problem. Share your experience here, and if anyone encounters the same problem, at least take a few detours. Please follow a few check errors:
can the code.py be executed?
Of course you may not be using the name code.py, I give the executable name is root.py
To check the permissions of the file, the code.py must be executable. If you do not have permission to execute it, add:
# chmod 755 code.py
At the same time, to ensure that the file header has such an instruction:
#!/usr/bin/env python
can the example of Hello World work?
Replace the contents of your code.py with the example of the web.py home page (don't forget to add the first line of instructions):
#!/usr/bin/env pythonimport weburls = ( ‘/(.*)‘, ‘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()
In general, this example can be run normally. This may indicate that our own program is having problems with the library referenced by Hello World.
Check the permissions of the egg cache
My program to link MySQL database, so used to Mysql-python, startup failure must have its share. Now try to add the import mysqldb in Hello World, and sure enough, it won't start! To see why, we used try-except to capture the exception thrown by the import mysqldb and output it to a Web page. Change the Get function of the above Hello class to:
try: import MySQLdbexcept Exception, e: return str(e);return ‘hello‘
Open localhost:8080, I see the following error message:
Can ' t extract file (s) to egg cache The following error occurred when trying to extract file (s) to the Python egg cache: [ Errno] Permission denied: '/sbin/.python-eggs ' The Python Egg cache directory is currently set to:/sbin/.python-eggs P Erhaps your account does not having write access to this directory? You can change the cache directory by setting the Python_egg_cache environment variable to point to an accessible director Y.
is also the authority problem, the solution has many kinds, I have changed its owner to be the user who runs lighttpd (my config file writes is daemon):
chown -R daemon.daemon /sbin/.python-eggs
which Python is used by lighttpd?
LIGHTTPD environment variables for the execution environment may not be the same as what you use in the shell! I have two python, one is the old Python 2.4 that comes with CentOS, and the other is Python 2.6 I compiled myself later, in my $PATH, Python 2.6 is in the directory that is preferred, but later found that Lighttpd used the old Python 2.4! If so, the simpler way is to write the full path of Python 2.6 on code.py's head, like mine:
#!/usr/local/bin/python
LIGHTTPD, web.py, spawning fcgi failed