Django 2.1 deployment on centos 7 with apache, mod_wsgi, python3 venv
I got everything to work. Here are the full steps:
yum install epel-release centos-release-scl
yum install python36 python36-devel httpd httpd-devel rh-python36-mod_wsgi`
Check if rh-python36-mod_wsgi
places everything in correct dirs
rpm -ql rh-python36-mod_wsgi
If found in:
/opt/rh/httpd24/root/etc/httpd/conf.modules.d/10-rh-python36-wsgi.conf
/opt/rh/httpd24/root/usr/lib64/httpd/modules/mod_rh-python36-wsgi.so
Move them to:
/etc/httpd/conf.modules.d/10-rh-python36-wsgi.conf
/etc/httpd/modules/mod_rh-python36-wsgi.so
Create python3 venv. if you're moving from somewhere, not creating in, check SEL to make sure apache can use it
cd /var/www
python36 -m venv django-venv
source /var/www/django-venv/activate
Configure virtual host at /etc/httpd/conf.d/django.conf
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com
WSGIDaemonProcess mysite python-home=/var/www/django-venv python-path=/var/www/mysite
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py
Alias /static /var/www/mysite/static
<Directory /var/www/mysite/static>
Require all granted
</Directory>
<Directory /var/www/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
If project is moved to /var/www
, restore correct SEL labels:
restorecon -Rv /var/www
Make project dir owned by apache:
chown -R apache:apache /var/www/mysite
If SQLite is used, allow SEL to permit apache access to it (improvement needed):
semanage boolean -p http_unified on