Monday, January 28, 2013

Quick Setup - Python mod_wsgi and XAMPP

Note: i have Preinstalled 32 bit python 2.7 on windows8
  1. Install XAMPP 1.7.7 from ( the latest XAMPP has apache 2.4 which isn't supported by mod_wsgi yet)
    sourceforge.net/projects/xampp/files/XAMPP Windows/1.7.7/xampp-win32-1.7.7-VC9-installer.exe 

  2. Download mod_wsgi.so from
    https://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-win32-ap22py27-3.3.so
  3. rename the .so file to mod_wsgi.so
  4. copy the mod_wsgi.so file to xampp/apache/modules directory (this is where all the other .so modules reside)
  5. Edit the httpd.conf file from (C:\xampp\apache\conf\httpd.conf) and add the below code at the end of page:

    LoadModule wsgi_module modules/mod_wsgi.so
    WSGIScriptAlias /<yourfoldername>"C:/xampp/htdocs/<yourfoldername>/"
    <Directory "C:/xampp/htdocs/<yourfoldername>">
        Order allow,deny
        Allow from all
    </Directory>

  6. Now Write the below hello world code in a myapp.py file and save it in the htdocs/<yourfoldername>
     
    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]
  7. visit your localhost/<yourfoldername>/myapp.py

    Cheers! on your first python WSGI application   !