I'm trying to get a Django + mod_fcgid setup working (mod_wsgi is tricky as I have a statically-linked Python. Don't ask.) While this was trivial on my Mac OS X development box, getting it running on the server has, so far, proven impossible.
With this configuration
LoadModule fcgid_module modules/mod_fcgid.so
FCGIDSocketPath run/mod_fcgid
FCGIDSharememPath run/mod_fcgid/fcgid_shm
ScriptAliasMatch /apps/([^/]+)(/.*)? /var/www/apps/$1/apache/dispatch.fcgi$2
<DirectoryMatch ^/var/www/apps/([^/]+)/apache>
SetHandler fcgid-script
Order allow,deny
Allow from all
Options +ExecCGI
</DirectoryMatch>
and this example dispatch.fcgi
:
#!/usr/bin/python
import sys
sys.path.insert(0, '/var/www/lib/python2.5/site-packages/flup-1.0.2.egg')
def myapp(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['This is my hello world test!\n']
if __name__ == '__main__':
from flup.server.fcgi import WSGIServer
WSGIServer(myapp).run()
Browsing to my test page yields a 500 error and in my Apache error logs, I get:
WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Status: 200 OK
Content-Type: text/plain
Content-Length: 29
This is my hello world test!
[Wed Sep 30 11:09:18 2009] [notice] mod_fcgid: process /var/www/apps/test/apache/dispatch.fcgi(31043) exit(server exited), terminated by calling exit(), return code: 0
There's my output, looking great -- except in Apache's error log, not my browser window.
When I remove my SetHandler
directive, the output goes right where I want it; obviously, it's running in ordinary CGI mode. That's not high-performing enough for my Django app, which gets 1-2 second page load times in that configuration.
So far, I have tried:
- flup 1.0.2, flup 1.0.3 development version, and a random fcgi.py written by flup's author
- threaded and prefork versions of my FastCGI server
- An RPM version of mod_fcgid and Apache's SVN version
- Python 2.4 and Python 2.5 (py2.4 isn't a realistic deployment option, but for testing...)
- AliasMatch / ScriptAliasMatch / mod_rewrite
Nothing seems to make any difference, except that using AliasMatch shows me the source, which is rather as I'd expected.
Again, this was absolutely trivial on Mac OS X. It Just Works with a comparable configuration.
Other than getting a better Python and using mod_wsgi (which is possible, if a pain), how do I make it work?
The problem: Some SELinux policy. I'm not expert enough to diagnose it, but doing:
makes everything work like a charm.