A. Install packages
[python 2.7]
yum install httpd yum install httpd-devel yum install python-pip pip install django yum install mod_wsgi # case of python 2.7
[python 3.X]
yum install pcre-devel wget http://mirrors.koehn.com/apache//httpd/httpd-2.4.23.tar.gz tar xvzf httpd-2.4.23.tar.gz configure make install
download site : https://github.com/GrahamDumpleton/mod_wsgi/releases
wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.5.7.tar.gz tar xvzf 4.5.7.tar.gz cd /<extract path> ./configure --with-apxs=/usr/local/apache2/bin/apxs make install
B. Create Django Project
django-admin startproject django_demo
C. Set mod_wsgi configuration
[python 2.7 – yum install httpd]
PATH : /etc/httpd/conf/
[python 3.x – manual install]
PATH : /usr/local/apache2
vi /etc/httpd/conf/httpd.conf
Listen <port> IncludeOptional conf.d/*.conf LoadModule wsgi_module modules/mod_wsgi.so
vi /etc/httpd/conf.d/django.conf
<VirtualHost *:80> WSGIScriptAlias / /opt/django_demo/django_demo/wsgi.py <Directory /opt/django_demo/django_demo> <Files wsgi.py> Require all granted </Files> </Directory> </VirtualHost>
D. Django wsgi.py
import os, sys path = os.path.abspath(__file__+'/../..') if path not in sys.path: sys.path.append(path) from django.core.wsgi import get_wsgi_application os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_demo.settings") application = get_wsgi_application()
chmod 777 /<path>/wsgi.py
E. Restart Apache
sudo service httpd.service restart
[manual start]
/usr/sbin/httpd
F. give permission
cat /etc/passwd | awk -F: '{print $1}' | grep apache sudo visudo ---------------------------- apache ALL=(ALL) ALL
G. Log
/var/log/httpd