How to set up Mod_WSGI for Python on Ubuntu
        Posted  
        
            by AutomatedTester
        on Server Fault
        
        See other posts from Server Fault
        
            or by AutomatedTester
        
        
        
        Published on 2009-12-06T14:46:21Z
        Indexed on 
            2010/04/10
            12:13 UTC
        
        
        Read the original article
        Hit count: 1054
        
Hi,
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
- sudo apt-get install libapache2-mod-wsgi
- sudo a2enmod mod-wsgi
- sudo /etc/init.d/apache2 restart
- 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 </Directory>
- sudo /etc/init.d/apache2 restart
- 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
Desired=Unknown/Install/Remove/Purge/Hold
| 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 <[email protected]>
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
Conffiles:
 /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 <[email protected]>
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!
FURTHER EDIT FOR RMYates
automatedtester@ubuntu:~$ apache2ctl -t -D DUMP_MODULES
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 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
automatedtester@ubuntu:~$
© Server Fault or respective owner