0

I've installed Python2.7 from source on a CentOS 6 VPS, and I'd like to get a Django site up and running. Unfortunately, everything I've Googled so far says that I'll need to install mod_wsgi, which means I'll need to reinstall Python2.7 with the --enable-shared flag.

  • Will I need to first uninstall Python2.7?
  • How can I install mod_wsgi without totally messing up my system?

Thanks in advance. I haven't been able to find a newbie-friendly guide.

Chad
  • 11
  • 1

1 Answers1

1

mod_wsgi is in the base repositories. You can just run yum install mod_wsgi

However, if you have been playing around installing Python from source, then it may well be that you have screwed up the Python environment. In that case, your best bet will be to reinstall the VPS from scratch and run yum install mod_wsgi.

Assuming you have deployed your Django project in /var/www/djangoproject you will have a tree something like:

/var/www/djangoproject/ ├── manage.py ├── djangoapp │ ├── __init__.py │ ├── models.py │ ├── tests.py │ └── views.py └── djangoproject ├── __init__.py ├── __init__.pyc ├── settings.py ├── settings.pyc ├── urls.py └── wsgi.py

Which will require an Apache conf (/etc/httpd/conf.d/djangoproject.conf) something like:

#WSGIPythonPath /var/www/djangoproject/djangoproject <VirtualHost *> ServerAdmin webmaster@example.com WSGIScriptAlias / /var/www/djangoproject/djangoproject/wsgi.py WSGIDaemonProcess myproj user=apache threads=3 <Directory /> Options FollowSymLinks AllowOverride None </Directory> DocumentRoot /tmp ServerName www.example.com ErrorLog /var/log/httpd/djangoproject_error_log CustomLog /var/log/httpd/djangoproject_access_log combined </VirtualHost>

chriscowley
  • 523
  • 4
  • 17
  • Thanks for the reply. I managed to get mod_wsgi installed using yum install as root, and successfully loaded it into apache. I added the .conf file you outlined above, but now I'm getting Internal Server Error when I type in the server address in a browser. I feel like I'm getting close here, but no cigar. – Chad Sep 23 '14 at 14:42
  • This is what I have: WSGIPythonPath /var/www/StoreWeb/StoreWeb ServerAdmin choodinator@gmail.com WSGIScriptAlias / /var/www/StoreWeb/StoreWeb/wsgi.py WSGIDaemonProcess myproj user=apache threads=3 Options FollowSymLinks AllowOverride None DocumentRoot /var/www/StoreWeb/StoreWeb/ ServerName www.example.com ErrorLog /var/log/httpd/StoreWeb-error_log CustomLog /var/log/httpd/StoreWeb-access_log combined – Chad Sep 23 '14 at 14:43
  • Looking at the error log, it looks like it can't import importlib. The relevant lines are "mod_wsgi (pid=15862): Target WSGI script '/var/www/StoreWeb/StoreWeb/wsgi.py' cannot be loaded as Python module." and "mod_wsgi (pid=15862): Exception occurred processing WSGI script '/var/www/StoreWeb/StoreWeb/wsgi.py'.", resulting in "ImportError: No module named importlib". I appears that wsgi is running in Python 2.6.: "/usr/lib64/python2.6/site-packages/django/core/wsgi.py" – Chad Sep 23 '14 at 15:08
  • Make sure you have all the necessary modules for your application installed on the server too. `sudo yum install python-importlib` in that case for example. – chriscowley Sep 24 '14 at 12:34
  • K, did that, now it's giving an 'invalid syntax' error in part of the django package in the server error log. And all the references from the log indicate that it's trying to use python2.6 instead of python2.7, which is what my site is written in. – Chad Sep 24 '14 at 14:12
  • Python 2.6 is the packaged version in Centos 6 and going to 2.7 will cause you a world of pain. If I were you I'd switch to Centos 7 and do as above. Or modify your syntax to be backward compatible. – chriscowley Sep 24 '14 at 19:44