09.20
I just installed mod_wsgi on my windows (yeah yeah, I know…) laptop, it turned out to be amazingly easy but I figured I’d put up notes on how to do it here anyways.
- Head over to http://adal.chiriliuc.com/mod_wsgi/ and fetch the latest (at the time of this writing it was revision_1018_2.3) apache module for your combination of python/apache
- mod_wsgi_py24_apache20 is for Python 2.4 and Apache 2.0
- mod_wsgi_py24_apache22 is for Python 2.4 and Apache 2.2
- mod_wsgi_py25_apache20 is for Python 2.5 and Apache 2.0
- mod_wsgi_py25_apache22 is for Python 2.5 and Apache 2.2
- Save the mod_wsgi.so file into your apache modules directory, for me it was located in C:\Program Files\Apache Software Foundation\Apache2.2\modules
- Create a directory somewhere outside of your webroot that will host your mod_wsgi-application, for simplicity’s sake I choose C:\wsgi
- Locate your httpd.conf-file and open it up in a text editor, it’s usually located in the conf-directory of your apache installation, for me it was: C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf
- Do a search for “LoadModule” and you’ll get a block of LoadModule-statements, put this on its own line there: LoadModule wsgi_module modules/mod_wsgi.so so it looks something like this:
#LoadModule usertrack_module modules/mod_usertrack.so LoadModule version_module modules/mod_version.so #LoadModule vhost_alias_module modules/mod_vhost_alias.so LoadModule wsgi_module modules/mod_wsgi.so
- Now find the <Directory> block for your web-root, for me it was: <Directory “C:/Program Files/Apache Software Foundation/Apache2.2/htdocs”>, under it add this block:
WSGIScriptAlias /wsgi "C:/wsgi/handler.py" <Directory "C:/wsgi"> AllowOverride None Options None Order deny,allow Allow from all </Directory>Notice that the two bold sections point at where I created my application directory so if you didn’t choose C:\wsgi you need to change this to reflect whatever directory you chose, the /wsgi part of the just before the first bold statement is the apache alias we want to use for our wsgi application – which in this case will be /wsgi also. Also note the use of forward instead of backwards slashes even when on windows.
-
The observant reader might’ve noticed the /handler.py at the end of the first bolded statement in the bullet point above, this is our handler script / entrypoint into our application. So add this code to handler.py and put it in C:\wsgi
def application(environ, start_response): status = '200 OK' output = 'Hello World!' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output] - Now just restart apache and go to http://localhost/wsgi and enjoy the beautiful world of python web development

No Comment.
Add Your Comment