I make apps for other people

Configuring Apache 2 in Ubuntu for WSGI Python

Posted by Chris Jones
On September 3rd, 2010 at 12:17

Permalink | Trackback | Links In |

Comments Off on Configuring Apache 2 in Ubuntu for WSGI Python
Posted in Python

There’s a great thread on the Ubuntu forums regarding this topic. For the purpose of keeping a record of what I needed to do:

  1. Install Apache 2
  2. Install libapache2-mod-wsgi

    # apt-get install libapache2-mod-wsgi
  3. Link the project directory to /var/www

    # cd /var/www
    # ln -s /some/path/DevTools
  4. Update /etc/apache2/sites-available/default

        <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews ExecCGI
            AllowOverride None
            Order allow,deny
            allow from all
            AddHandler cgi-script .cgi
            AddHandler wsgi-script .wsgi
  5. Restart Apache

    # apache2ctl restart
  6. Create the tester script, /var/www/DevTools/tester.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]
  7. Verify your tester by going to http://localhost/DevTools/tester.wsgi. The output should be:

    Hello World!

If you get any 500 Server Error responses, check /var/log/apache2/error.log first. mod_python does a better job with error reporting than WSGI but is, in my experience, a more fragile framework for configuring and developing web apps.

Comments are closed.