Bryan Lawrence
... personal wiki, blog and notes
Exploring Web Server Backends - installing fastcgi and lighttpd
A few months ago, I was investigating web server options (one, two, three). I finished that series saying I needed to investigate wsgi. Well that time has come, there are a number of reasons why wsgi and fastcgi (or scgi) may be important to us. However I'm a little bit wary about Apache and fastcgi after getting the impression that lighttpd may be the way to go for fastcgi. So, this note is a list of my experiences getting a wsgi hello world going on my dapper laptop. (As usual, my interest in doing this for myself is to understand the major issues, not because I'm personally going to be working on this).
(I'm doing this using my own /usr/local/bin/python2.5 rather than the system default python.)
Got Lighttpd:
sudo apt-get install lighttpd
(This started a process running under www-data, and put scripts in /etc/init.d, so I may well have this automatically starting when I boot, which isn't really what I want on a laptop ... I'll investigate that later).
Got flup, noting that no 2.5 egg existed, I had to get a tar ball, and setup install it (nb: remember using my local python):
wget http://www.saddi.com/software/flup/dist/flup-r2030.tar.gz tar xzvf flup-r2030.tar.gz cd flup-r2030 sudo python setup.py install
Following cleverdevil (Jonathan Lacour) I grabbed scgi while I was at it.
sudo easy_install scgi
but for my first steps, I'm planning on getting vanilla fastcgi working. I may play with scgi later. Meanwhile for fastcgi, I'm basically following cleverdevil again, adjusted for my ubuntu apt-installed lightty.
I modified the file ''10-fastcgi.conf in /etc/lighttpd/conf-available to be
## FastCGI programs have the same functionality as CGI programs,
## but are considerably faster through lower interpreter startup
## time and socketed communication
##
## Documentation: /usr/share/doc/lighttpd-doc/fastcgi.txt.gz
## http://www.lighttpd.net/documentation/fastcgi.html
server.modules += ( "mod_fastcgi" )
## Start a FastCGI server for python test example
fastcgi.debug = 1
fastcgi.server = ( ".fcgi" =>
( "localhost" =>
(
"socket" => "/tmp/fcgi.sock",
"min-procs" => 2
)
)
)
and put a sym link to this file into my /etc/lighttpd/conf-enabled directory. (Update 27 Oct: Oops, I had a non-working version of 10-fastcgi.conf here until today. The one above is the one I have working ... today).
I put the test file in my /var/www directory as test.fcgi:
#!/usr/local/bin/python
from flup.server.fcgi import WSGIServer
def myapp(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['Hello World!\n']
WSGIServer(myapp, bindAddress = '/tmp/fcgi.sock').run()
***
highlight file error
***
And I ran it:
python test.fcgi
and it sits there running.
Now, trying to access it on http://localhost.localdomain/test.fcgi results in a 500 Internal Server Error. A check in the access log showed many instances of this (associated with much head scratching and time wasting):
2006-10-25 21:54:06: (mod_fastcgi.c.2669) fcgi-server re-enabled: unix:/tmp/fcgi.sock 2006-10-26 08:09:30: (mod_fastcgi.c.1739) connect failed: Permission denied on unix:/tmp/fcgi.sock 2006-10-26 08:09:30: (mod_fastcgi.c.2851) backend died, ...
Eventually the penny dropped. The server is running as www-data which has no access permissions to the unix domain socket (/tmp/fcgi.sock) created by the user (whether me or root) running the python fast.cgi server code ...
So, I changed the permissions on /var/www to allow www-data access, and reran the python command:
sudo su www-data python test.fcgi
And lo and behold, I get a "Hello World" on http://localhost.localdomain/fast.cgi.
Trackbacks (1)
“Getting” Python Paste (from "lirico" on Sunday 29 October, 2006)
No comments yet
Comments presently read-only.
DISCLAIMER: This is a personal blog. Nothing written here reflects an official opinion of my employer or any funding agency.
