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   !

3 comments:

  1. Hello when I pasted this snippet in,

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



    httpd.conf file


    I got this error,

    19:36:36 [Apache] Status change detected: stopped
    19:36:36 [Apache] Error: Apache shutdown unexpectedly.
    19:36:36 [Apache] This may be due to a blocked port, missing dependencies,
    19:36:36 [Apache] improper privileges, a crash, or a shutdown by another method.
    19:36:36 [Apache] Press the Logs button to view error logs and check
    19:36:36 [Apache] the Windows Event Viewer for more clues
    19:36:36 [Apache] If you need more help, copy and post this
    19:36:36 [Apache] entire log window on the forums

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete