This guide is intended for debian stretch, so config filenames could differ in you case.
To run python code Apache uses mod-wsgi, so we need to intall it first.
apt install apache2 apache libapache2-mod-wsgi-py3 #commit the py3 to use python2
Make sure that mod-wsgi is installed and enabled, it should be present in /etc/apache2/mods-enabled
.
If it is not there enable it:
sudo a2enmod wsgi
restart/reload apache, using you process management
sudo systemctl restart apache2
Add this to your /etc/apache.conf file, (httpd.conf in some systems)
WSGIScriptAlias / /path/to/project/app/wsgi.py
#WSGIPythonHome /path/to/venv
WSGIPythonPath /path/to/project
<Directory /path/to/project/app>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Replace /path/to/project/app with your app’s path and /path/to/project with your project’s path. Let’s say you created a project named personal_website in your home directory and inside it an app called blog.
Then the config will look like this
WSGIScriptAlias / /home/iduoad/personal_website/blog/wsgi.py
#WSGIPythonHome /path/to/venv
WSGIPythonPath /home/iduoad/personal_website
<Directory /home/iduoad/personal_website/blog>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Restart apache and congratulations.
This was to get started with django with apache2 for one app, Also Django doc advices to serve static files separately. So learn more read the docs