Thursday, January 14, 2010

How to build mod_wsgi,web.py with httpd and python from source code

It is best to compile everything from source code.

Version used
Python: 2.7 (with shared library)httpd 2.2.17 (with shared DSO support)WSGI (integrating with httpd): mod_wsgi 3.3
Web framework: web.py 0.34

Compile Python for shared lib

./configure --prefix= --enable-shared


Set up LD_LIBRARY_PATH so that running "python" would find its shared lib
export LD_LIBRARY_PATH=${python-lib}:$LD_LIBRARY_PATH


Compile (apache) httpd Add DSO support
./configure --prefix= --enable--module=module_so



Compile mod_wsgi
./configure --with-apxs=$APACHE_HOME/bin/apxs --with-python=$PYTHON_BIN/python

Configure httpd.conf for mod_wsgi



LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /wsgi/ /u/local/www/wsgi-scripts/

WSGIApplicationGroup admin-scripts
Order allow,deny
Allow from all

WSGIProcessGroup example1.com
WSGIDaemonProcess example1.com processes=2 threads=15 display-name=example1.com

Install a sample python code under /u/local/www/wsgi-scripts/sniff
import sys
def application(environ, start_response):
status = '200 OK'
output = 'sys.version= %s\nsys.prefix=%s\n' % (sys.version, sys.prefix)
output += 'sys.path= %s\n' % (sys.path)

response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output]