Installing Apache mod_wsgi in Arch Linux

This covers how to install and start using mod_wsgi with Apache on Arch Linux.

Install WSGI for Apache

sudo pacman -S mod_wsgi

For more details refer to Arch Linux Wiki page on mod_wsgi.

Add the module to Apache's config file /etc/httpd/conf/httpd.conf

LoadModule wsgi_module modules/

Tell Apache when and where to use WSGI

Apache will only run WSGI when you tell it to. By adding a WSGIScriptAlias in the Apache host entry, Apache will know to when to invoke WSGI. You can create your own Python file, but it has to follow a few rules to return data correctly. Applications like Django create a file for you, and you just need to point Apache at that file.

This script alias line will alias the URL /myapp to the file.

WSGIScriptAlias /myapp /srv/http/

Example Apache VirtualHost entry

<VirtualHost *:80>
    DocumentRoot "/srv/http/"
    ErrorLog "/var/log/httpd/"
    CustomLog "/var/log/httpd/" common
    WSGIScriptAlias / /srv/http/

Example file

def wsgi_app(environ, start_response):
    output = "<html><body><h1>WSGI working!</ht></body></html>\n".encode('utf-8')
    status = '200 OK'
    headers = [('Content-type', 'text/html'),
               ('Content-Length', str(len(output)))]
    start_response(status, headers)
    yield output

# mod_wsgi needs the "application" variable to serve our small app
application = wsgi_app