Updated: 19 November 2026 · Applies to: Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9

mod_wsgi lets Apache run a Django project directly. This guide assumes the project is in /srv/mysite with a virtual environment in /srv/mysite/venv (see "How to install and start a project with Django framework on CentOS 7?").

The operating system versions in the original guide (CentOS 7, Ubuntu 16.04/18.04, Debian 8/9) are no longer supported, so this guide uses Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9.

Note: Django 6.1 (the current version) needs Python 3.12 or newer. Ubuntu 24.04 has Python 3.12. On AlmaLinux 9 / Rocky Linux 9 install python3.12 as shown (the default Python 3.9 is too old). On Debian 12 (Python 3.11) pip installs Django 5.2 LTS, which is supported until April 2028.

Install mod_wsgi

Ubuntu 24.04 / Debian 12: the packaged module matches the system Python.

apt install apache2 libapache2-mod-wsgi-py3

AlmaLinux 9 / Rocky Linux 9: the packaged module is built for Python 3.9, so build mod_wsgi inside the Python 3.12 virtual environment instead:

dnf install httpd httpd-devel gcc python3.12-devel
source /srv/mysite/venv/bin/activate
pip install mod_wsgi
mod_wsgi-express module-config > /etc/httpd/conf.modules.d/20-wsgi.conf

Apache configuration

<VirtualHost *:80>
    ServerName example.com
    Alias /static/ /srv/mysite/static/
    <Directory /srv/mysite/static> Require all granted </Directory>
    WSGIDaemonProcess mysite python-home=/srv/mysite/venv python-path=/srv/mysite
    WSGIProcessGroup mysite
    WSGIScriptAlias / /srv/mysite/mysite/wsgi.py
    <Directory /srv/mysite/mysite>
        <Files wsgi.py> Require all granted </Files>
    </Directory>
</VirtualHost>

Run python manage.py collectstatic (with STATIC_ROOT = "/srv/mysite/static"), set DEBUG = False and ALLOWED_HOSTS, then reload Apache.

Note: On AlmaLinux 9 / Rocky Linux 9 SELinux must allow Apache to read the project: semanage fcontext -a -t httpd_sys_content_t "/srv/mysite(/.*)?" && restorecon -R /srv/mysite.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket