简体   繁体   中英

Cannot deploy Official Django tutorial on Apache (mod_wsgi)

I know this question seems to have been asked and answered many times, but I have now wasted over 48 hours now trying various methods provided by other answers and I cannot seem to deploy the official django tutorial to my local Apache webserver (Apache 2.4 on Ubuntu 18.04, Python 3.6.5). Here's what I did.

I created a virtualenv

virtualenv outlier
cd outlier
pip3 install django
django-admin startproject mysite

I created my app and installed the mod_wsgi version appropriate for my python version (I tried the apt install and the setup.py install methods).

Then I configured /etc/apache2/sites-enabled/000-default.conf as follows:

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

<VirtualHost *:80>
        LogLevel info
        DocumentRoot /srv/outlier
        ServerName outlier.tuhao
        WSGIDaemonProcess outlier user=www-data group=www-data python-path="/srv/outlier" python-home="/srv/outlier/lib/python3.6/site-packages"
        WSGIProcessGroup outlier
        WSGIScriptAlias / /srv/outlier/outlier/wsgi.py

        <Directory /srv/outlier>
                Require all granted
        </Directory>
</VirtualHost>

Just to be sure, I also did a sudo chown -R www-data:www-data /srv/ and a sudo chmod -R 777 /srv/ to avoid any permissions ding-dongs.

and restarted apache with sudo service apache2 restart . Unfortunately, immediately after restarting, the apache logs start incessantly spamming the following:

Current thread 0x00007faa78e0abc0 (most recent call first): [Mon Jun 04 15:34:55.664080 2018] [core:notice] [pid 1932] AH00051: child pid 5058 exit signal Aborted (6), possible coredump in /etc/apache2 Fatal Python error: Py_Initialize: Unable to get the locale encoding ModuleNotFoundError: No module named 'encodings'

I should just ask the question first (maybe without posting), because I always end up finding the solution shortly after.

This line: WSGIDaemonProcess outlier user=www-data group=www-data python-path="/srv/outlier" python-home="/srv/outlier/lib/python3.6/site-packages"

needs to become this line: WSGIDaemonProcess outlier user=www-data group=www-data python-path="/srv/outlier" python-home="/srv/outlier"

I swear I had unsuccessfully tried it before but there was probably something else not right at that stage.

I'll leave the question and answer here for others that may have come from the tutorial without knowing what to do next. Or admins may delete if so desired.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM