I am trying to setup MOD_WSGI on my Ubuntu box. I have found steps that said I needed to do the following steps I found at http://ubuntuforums.org/showthread.php?t=833766

  1. sudo apt-get install libapache2-mod-wsgi
  2. sudo a2enmod mod-wsgi
  3. sudo /etc/init.d/apache2 restart
  4. sudo gedit /etc/apache2/sites-available/default and update the Directory
<Directory /var/www/>
  Options Indexes FollowSymLinks MultiViews ExecCGI

  AddHandler cgi-script .cgi
  AddHandler wsgi-script .wsgi

  AllowOverride None
  Order allow,deny
  allow from all
  1. sudo /etc/init.d/apache2 restart
  2. Created test.wsgi with

    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]

Step 2 fails because it says it can't find mod-wsgi even though the apt-get found it. If I carry on with the steps the python app just shows as plain text in a browser.

Any ideas what I have done wrong?

EDIT: Results for questions asked

automatedtester@ubuntu:~$ dpkg -l libapache2-mod-wsgi
| Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                   Version                                Description
ii  libapache2-mod-wsgi                    2.5-1                                  Python WSGI adapter module for Apache
automatedtester@ubuntu:~$ dpkg -s libapache2-mod-wsgi
Package: libapache2-mod-wsgi
Status: install ok installed
Priority: optional
Section: python
Installed-Size: 376
Maintainer: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com>
Architecture: i386
Source: mod-wsgi
Version: 2.5-1
Depends: apache2, apache2.2-common, libc6 (>= 2.4), libpython2.6 (>= 2.6), python (>= 2.5), python (<< 2.7)
Suggests: apache2-mpm-worker | apache2-mpm-event
 /etc/apache2/mods-available/wsgi.load 06d2b4d2c95b28720f324bd650b7cbd6
 /etc/apache2/mods-available/wsgi.conf 408487581dfe024e8475d2fbf993a15c
Description: Python WSGI adapter module for Apache
 The mod_wsgi adapter is an Apache module that provides a WSGI (Web Server
 Gateway Interface, a standard interface between web server software and
 web applications written in Python) compliant interface for hosting Python
 based web applications within Apache. The adapter provides significantly
 better performance than using existing WSGI adapters for mod_python or CGI.
Original-Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
Homepage: http://www.modwsgi.org/
automatedtester@ubuntu:~$ sudo a2enmod libapache2-mod-wsgi
ERROR: Module libapache2-mod-wsgi does not exist!
automatedtester@ubuntu:~$ sudo a2enmod mod-wsgi
ERROR: Module mod-wsgi does not exist!


automatedtester@ubuntu:~$ apache2ctl -t -D DUMP_MODULES
apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName
Loaded Modules:
 core_module (static)
 log_config_module (static)
 logio_module (static)
 mpm_worker_module (static)
 http_module (static)
 so_module (static)
 alias_module (shared)
 auth_basic_module (shared)
 authn_file_module (shared)
 authz_default_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgid_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 python_module (shared)
 setenvif_module (shared)
 status_module (shared)
Syntax OK
  • What can't find mod_wsgi, Apache or Python? – Dana the Sane Dec 6 '09 at 17:07
  • 1
    the a2enmod command could not find mod_wsgi – AutomatedTester Dec 7 '09 at 8:44

I have found that this is a known bug with mod_wsgi apt-get package that is over a year old! Details at http://www.mail-archive.com/ubuntu-bugs@lists.ubuntu.com/msg1147225.html. The apt-get package did not have the wsgi.load file so that needed to be created by doing the steps in the link above.

Thanks to everyone that helped!


See if the module is actually loaded properly with:

apache2ctl -t -D DUMP_MODULES
  • it doesn't look like it has loaded properly – AutomatedTester Dec 8 '09 at 17:58

As far as I can see, you haven't loaded the mod_wsgi module into your httpd.conf.

I'd first try adding the wsgi files to the mods-enabled directory of Apache.

sudo ln -s /etc/apache2/mods-available/wsgi.load /etc/apache2/mods-enabled
sudo ln -s /etc/apache2/mods-available/wsgi.conf /etc/apache2/mods-enabled

Then restart Apache and it should work.


First confirm that the WSGI module is actually installed:

dpkg -l libapache2-mod-wsgi

This should give you output including name, version, etc. - look for the letters on the left of the name, this indicates current status of the package. To check manually, look in /etc/apache2/mods-available/ and you should see both wsgi.conf and wsgi.load. If these exist, they should have corresponding symlinks in /etc/apache2/mods-enabled/.

Should either set not exist, start by fixing that first - you can't interpret python code via apache if apache can't find the interpreter. Also, your test.py script will not work given the AddHandler directives you've configured - that directive tells apache to pass files of a certain extension to the relevant handler. Make your script test.wsgi or change the AddHandler directive.

  • the test.py was a typo in the question. I meant to put test.wsgi. – AutomatedTester Dec 7 '09 at 8:43
  • Fine, but have you confirmed that the module is installed and correctly linked in per the instructions above? – Zayne S Halsall Dec 7 '09 at 17:33
  • I have put the information that you asked for in the question. – AutomatedTester Dec 7 '09 at 19:57
  • Not all the information - please check manually if the files wsgi.conf and wsgi.load in /etc/apache2/mods-available/ are symbolically linked to /etc/apache2/mods-enabled as requested. A simple long listing of the directory should suffice (i.e. ls -alh /etc/apache2/mods-enabled/). – Zayne S Halsall Dec 13 '09 at 13:24

Did you add the LoadModule line to actually cause mod_wsgi to be loaded? What is the actual error message and where is it coming from? See:


for low level instructions. Since you are using binary packages you can skip the compilation, but you still need to cause mod_wsgi to be loaded. Where/how you may do this is going to be determined to a degree by your Linux distribution. Based on that guide you are meant to have run:

sudo a2enmod mod-wsgi
sudo /etc/init.d/apache2 restart

Did you actually do that?


Reading your question again it is obvious. You said that files with .wsgi extension are handled by mod_wsgi but then you gave the file a .py extension. Use .wsgi instead.

  • the test.py was a typo in the question. I meant to put test.wsgi. I did run the a2enmod but it said that it could not find mod_wsgi as I put at the end of my question – AutomatedTester Dec 7 '09 at 8:44

You may look at the syntax of your python first. Check if you really have 4 spaces after the function definition. Check the python file by running it first via terminal

$ python /var/www/py/wsgi_handler.wsgi

then if no errors appear, run it via web browser.


and by the way, you seem to have missed something for your apache configuration/ virtualhost file. Put this inside the tags

WSGIScriptAlias /wsgi /var/www/py/wsgi_handler.py

by the way, apt has no problems when installing the wsgi module. I have tested it just now and have successfully ran a python script on my web browser.


Not sure if this is relevant, but after running:

apt-get install libapache2-mod-wsgi

... the following files did not exist:


Reinstalling did not seem to replace the missing files. Weird! However, purge seemed do to the trick:

apt-get install libapache2-mod-wsgi
apt-get purge libapache2-mod-wsgi
apt-get install libapache2-mod-wsgi

# ls /etc/apache2/mods-available/ | grep wsgi

protected by Community Aug 23 '11 at 10:44

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.