If you’ve read up on Part 1, you should have a running virtual environment with the latest Django installation and Python 2.7 installed. My next task was to get Apache with Mod_WSGI running correctly in order to host my Overview app. After hours and days of tinkering, I finally got it working and here are my notes for record keeping.
[leo@overview Downloads]# wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.4.11.tar.gz [leo@overview Downloads]# tar xf 4.4.11.tar.gz [leo@overview Downloads]# cd mod_wsgi-4.4.11 [leo@overview mod_wsgi-4.4.11]# ./configure --with-python=/usr/local/bin/python2.7 [leo@overview mod_wsgi-4.4.11]# LD_RUN_PATH=/usr/local/lib make [leo@overview mod_wsgi-4.4.11]# make install
Here, I am downloading and installing the latest Mod_WSGI. You can see in the configure command that I chose to specify the python to use. A mistake I made in this process is to use the virtual environment python instead of the path directly to the python2.7 installation. After reading Some tips for setting up Apache and mod_wsgi by Marc Abramowitz, I decided to also use
LD_RUN_PATH in my make command.
Last, we have to load the mod_wsgi module into apache. Adding this line to the httpd.conf file made it so.
LoadModule wsgi_module modules/mod_wsgi.so
After restarting Apache, I can now see that Mod_WSGI is running by taking a look at the httpd error logs.
Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3 mod_ssl/2.2.15 OpenSSL/1.0.1e-fips mod_wsgi/4.4.11 Python/2.7.5 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
My apache config file has come down to the following:
<VirtualHost *:80> ServerName Overview ServerAlias overview.labs.lenovo.com/SRM Alias /static /home/Django/Overview/rsl/static/ Alias /uploads /home/Django/Overview/static/uploads/ <Directory /var/www/html/Overview/static> Order deny,allow Allow from all </Directory> <Directory /home/Django/Overview/rsl/static/uploads> Order deny,allow Allow from all </Directory> WSGIDaemonProcess Overview python-path=/home/Django/Overview:/home/virtualenvs/django_env/lib/python2.7/site-packages WSGIScriptAlias /SRM /home/Django/Overview/Overview/wsgi.py process-group=Overview <Directory /home/Django/Overview/Overview> <Files wsgi.py> Order deny,allow Allow from all </Files> </Directory> </VirtualHost>
And my wsgi.py file is:
import os, sys sys.path.append('/home/Django') sys.path.append('/home/Django/Overview/') from django.core.wsgi import get_wsgi_application os.environ["DJANGO_SETTINGS_MODULE"] = "Overview.settings" application = get_wsgi_application()
If you are running into issues with your Mod_WSGI installation with the use of virtual environments, I suggest you take a look at the documentation here.