Darryl Ong
Darryl Ong

Reputation: 33

Deploying Django on Apache with mod_wsgi

I'm currently trying to set up a Django application on Apache on a Centos server, with the use of mod_wsgi. This is set up to run on https. It is on virtualenv.

However, currently it gives a 504 Gateway Timeout error.

Error log:

(2)No such file or directory: mod_wsgi (pid=15007): Unable to stat Python home /bin/virtualenv:/var/www/django/mysite/mysite/lib/python3.6/site-packages. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path.
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

httpd.conf

<VirtualHost *:443>
ServerName mysite.example.com
ServerAlias www.mysite.example.com
# DocumentRoot /var/www/django/mysite

LogLevel info

ErrorLog /etc/httpd/logs/mysite_error.log


Alias /static /var/www/django/mysite/static

<Directory /var/www/django/mysite/static>
  Require all granted
</Directory>

<Directory /var/www/django/mysite/mysite>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

WSGIDaemonProcess mysite python-home=/bin/virtualenv:/var/www/django/mysite/mysite/lib/python3.6/site-packages
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/django/mysite/mysite/wsgi.py
WSGIApplicationGroup %{GLOBAL}


SSLEngine on
SSLProtocol all -SSLv2

SSLCompression off

SSLCertificateFile /etc/pki/tls/certs/mysite.cert.pem
SSLCertificateKeyFile /etc/pki/tls/private/mysite.key.pem
SSLCertificateChainFile /etc/pki/tls/certs/mysite.chain.pem

</VirtualHost>

Upvotes: 2

Views: 2739

Answers (1)

Graham Dumpleton
Graham Dumpleton

Reputation: 58523

This is incorrect:

WSGIDaemonProcess mysite python-home=/bin/virtualenv:/var/www/django/mysite/mysite/lib/python3.6/site-packages

Review:

The python-home value should be a single directory, which is the same as sys.prefix for Python when using virtual environment. Do not added site-packages directory.

Most important, mod_wsgi must be compiled for same Python version as was used to create the virtual environment. You can't use mod_wsgi compiled for Python 2.7 with virtual environment created with Python 3.6.

Check what version of Python mod_wsgi was compiled for using:

Upvotes: 1

Related Questions