How to set up Mod_WSGI for Python on Ubuntu

Solution 1:

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/[email protected]/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!

Solution 2:

See if the module is actually loaded properly with:

apache2ctl -t -D DUMP_MODULES

Solution 3:

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.

Solution 4:

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.

Solution 5:

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:

http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide

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?


EDIT

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.