I would like to deploy a site that was created with Django. The production environment is a rented virtual server.
I would like to deploy the application with Django. Therefore, I changed all settings according to the documentation (especially, created a folder from where all collected static files can be served) and tried it out on my local development machine.
Because the site is now ready I pushed the whole project to the virtual server. I use Ubuntu 14.04 LTS both on my development machine and on the virtual host. Although I tested the project on my local machine with the apache I experienced some difficulties during the deployment phase. The project is called kleyboldt. My virtualenv is stored in the /root directory and the project lives under /var/www. Here are the important files:
/etc/apache2/sites-available/mks.conf
WSGIDaemonProcess mathias-kleyboldt-stiftung.de python-path=/var/www/kleyboldt_homepage$
WSGIProcessGroup mathias-kleyboldt-stiftung.de
<VirtualHost *:80>
DocumentRoot /var/html/kleyboldt_homepage
WSGIScriptAlias / /var/www/kleyboldt.wsgi
ServerName mathias-kleyboldt-stiftung.de
ServerAlias www.mathias-kleyboldt-stiftung.de
<LocationMatch "\.(jpg|css|gif|pdf|ico)$">
SetHandler None
</LocationMatch>
Alias /media/ /var/www/kleyboldt_homepage/static/media/
Alias /static/ /var/www/kleyboldt_homepage/static/static-only/
<Directory /var/www/kleyboldt_homepage/>
Require all granted
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/kleyboldt_homepage/static/static-only>
Require all granted
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/www/kleyboldt_homepage/apache_error.log
LogLevel debug
</VirtualHost>
/var/www/kleyboldt.wsgi
import os
import sys
sys.path.append('/var/www/kleyboldt_homepage')
os.environ['DJANGO_SETTINGS_MODULE'] = 'kleyboldt_homepage.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
The project structure under /var/www/kleyboldt_homepage:
root@somewhere:/var/www/kleyboldt_homepage# ls
apache_error.log homepage index.html manage.py static
db.sqlite3 homepage.log kleyboldt_homepage site.txt
To manage the dependencies for this project I used the virtualenvwrapper to create a env under /root/virtualenvs called kleyboldt-homepage:
root@somewhere:~/virtualenvs/kleyboldt-homepage/lib/python2.7/site-packages# ls
crispy_forms markdown2.pyc
django markdown_deux
Django-1.6.5.dist-info _markerlib
django_crispy_forms-1.4.0-py2.7.egg-info pagedown
django_grappelli-2.5.3-py2.7.egg-info pip
django_markdown_deux-1.0.4-py2.7.egg-info pip-1.5.4.dist-info
django_pagedown-0.1.0-py2.7.egg-info pkg_resources.py
easy_install.py pkg_resources.pyc
easy_install.pyc setuptools
grappelli setuptools-2.2.dist-info
markdown2-2.2.1-py2.7.egg-info south
markdown2.py South-1.0-py2.7.egg-info
After reloading the apache2 server and refreshing the page I get a 500 Internal Server error. I looked it up in the debug file I specified in the apache conf file.
/var/www/kleyboldt_homepage/apache_error.log
[Mon Aug 18 17:04:50.226000 2014] [authz_core:debug] [pid 966:tid 139697743423232] mod_authz_core.c(802): [client 92.224.193.119:56235] AH01626: authorization result of Require all granted: granted
[Mon Aug 18 17:04:50.226104 2014] [authz_core:debug] [pid 966:tid 139697743423232] mod_authz_core.c(802): [client 92.224.193.119:56235] AH01626: authorization result of <RequireAny>: granted
[Mon Aug 18 17:04:50.226227 2014] [authz_core:debug] [pid 966:tid 139697743423232] mod_authz_core.c(802): [client 92.224.193.119:56235] AH01626: authorization result of Require all granted: granted
[Mon Aug 18 17:04:50.226239 2014] [authz_core:debug] [pid 966:tid 139697743423232] mod_authz_core.c(802): [client 92.224.193.119:56235] AH01626: authorization result of <RequireAny>: granted
[Mon Aug 18 17:04:50.241584 2014] [:info] [pid 965:tid 139697924556544] [remote 92.224.193.119:14076] mod_wsgi (pid=965, process='mathias-kleyboldt-stiftung.de', application='mathias-kleyboldt-stiftung.de|'): Loading WSGI script '/var/www/kleyboldt.wsgi'.
[Mon Aug 18 17:04:50.242108 2014] [:error] [pid 965:tid 139697924556544] [remote 92.224.193.119:14076] mod_wsgi (pid=965): Target WSGI script '/var/www/kleyboldt.wsgi' cannot be loaded as Python module.
[Mon Aug 18 17:04:50.242118 2014] [:error] [pid 965:tid 139697924556544] [remote 92.224.193.119:14076] mod_wsgi (pid=965): Exception occurred processing WSGI script '/var/www/kleyboldt.wsgi'.
[Mon Aug 18 17:04:50.242137 2014] [:error] [pid 965:tid 139697924556544] [remote 92.224.193.119:14076] Traceback (most recent call last):
[Mon Aug 18 17:04:50.242161 2014] [:error] [pid 965:tid 139697924556544] [remote 92.224.193.119:14076] File "/var/www/kleyboldt.wsgi", line 7, in <module>
[Mon Aug 18 17:04:50.242215 2014] [:error] [pid 965:tid 139697924556544] [remote 92.224.193.119:14076] import django.core.handlers.wsgi
[Mon Aug 18 17:04:50.242233 2014] [:error] [pid 965:tid 139697924556544] [remote 92.224.193.119:14076] ImportError: No module named django.core.handlers.wsgi
The import of django.core.handlers.wsgi seems to fail. I checked my python path specified behind the WSGIDaemonProcess but everything seems to be fine. But the import is still failing. Does anybody know how to fix this?