I've followed this deploy tutorial of Django for Apache, and did everything as in there. When I try to enter the page with server's ip, I get
Forbidden
You don't have permission to access / on this server.
Apache/2.4.29 (Ubuntu) Server at <my-ip> Port 80
Running the app with python manage.py runserver 0.0.0.0:8000
works fine and I can access the app.
Via the apache2 logs I got:
Current thread 0x00007fc84606fbc0 (most recent call first):
[Wed Aug 14 01:11:51.141895 2019] [core:notice] [pid 31839:tid 140498145049536] AH00051: child pid 32108 exit signal Aborted (6), possible coredump in /etc/apache2
$preter 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'
My config file:
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/ernest/[my-project-name]/static
<Directory /home/ernest/[my-project-name]/static>
Require all granted
</Directory>
Alias /media /home/ernest/[my-project-name]/datagather/uploaded_files
<Directory /home/ernest/[my-project-name]/datagather/uploaded_files>
Require all granted
</Directory>
<Directory /home/ernest/[my-project-name]/[my-project-name]/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/ernest/[my-project-name]/[my-project-name]/wsgi.py
WSGIDaemonProcess my_app python-path=/home/ernest/[my-project-name] python-home=/home/[my-project-name]/venv
WSGIProcessGroup my_app
</VirtualHost>
I've done following changes to [my-project-name]/settings.py:
DEBUG = False
ALLOWED_HOSTS = ['[my-server-ip]', 'localhost']
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'datagather/uploaded_files/')
MEDIA_URL = '/datagather/uploaded_files/'
I have also set up proper permissions using
sudo chown :www-data [my-project-name]/db.sqlite3
sudo chmod 664 [my-project-name]/db.sqlite3
sudo chown :www-data [my-project-name]/
sudo chown -R :www-data [my-project-name]/datagather/uploaded_files/
sudo chmod -R 775 [my-project-name]/datagather/uploaded_files
And it looks like this:
ls -la
total 1384
drwxrwxr-x 10 666 www-data 4096 Aug 14 01:05 .
drwx------ 5 ernest ernest 4096 Aug 14 00:40 ..
drwxrwxr-x 6 ernest ernest 4096 Aug 13 23:25 [dir-in-project]
drwxrwxr-x 6 ernest ernest 4096 Aug 13 23:25 [dir-in-project]
drwxrwxr-x 7 ernest ernest 4096 Aug 13 23:56 datagather
-rw-rw-r-- 1 ernest www-data 212992 Aug 13 23:17 db.sqlite3
-rw-rw-r-- 1 ernest ernest 0 Aug 13 23:17 __init__.py
-rw-rw-r-- 1 ernest ernest 642 Aug 13 23:17 manage.py
drwxrwxr-x 3 ernest ernest 4096 Aug 14 01:30 [my-project-name]
-rw-rw-r-- 1 ernest ernest 183 Aug 13 23:17 requirements.txt
-rw-rw-r-- 1 ernest ernest 1152635 Aug 13 23:34 simple_logs.log
drwxrwxr-x 8 ernest ernest 4096 Aug 13 23:25 static
drwxrwxr-x 7 ernest ernest 4096 Aug 13 23:25 [dir-in-project]
drwxrwxr-x 8 ernest ernest 4096 Aug 13 23:25 [dir-in-project]
drwxr-xr-x 7 root root 4096 Aug 14 01:08 venv
Current port usage looks like this (enabled http-traffic and port 80 before)
sudo lsof -i -P -n | grep LISTEN
systemd-r 846 systemd-resolve 13u IPv4 15597 0t0 TCP 127.0.0.53:53 (LISTEN)
sshd 976 root 3u IPv4 18092 0t0 TCP *:22 (LISTEN)
sshd 976 root 4u IPv6 18103 0t0 TCP *:22 (LISTEN)
apache2 3265 root 4u IPv6 870246 0t0 TCP *:80 (LISTEN)
apache2 3280 www-data 4u IPv6 870246 0t0 TCP *:80 (LISTEN)
apache2 3281 www-data 4u IPv6 870246 0t0 TCP *:80 (LISTEN)
Libraries used in the app (made with pip freeze):
Django==2.2.3
et-xmlfile==1.0.1
jdcal==1.4.1
numpy==1.16.4
openpyxl==2.6.2
pandas==0.24.2
python-dateutil==2.8.0
pytz==2019.1
six==1.12.0
sqlparse==0.3.0
Unidecode==1.1.1
xlrd==1.2.0
The app was developed on Python 3.7.1, however on 3.6.8 it seems to work just fine, based on the development server.
I have no idea what am I doing wrong at this point. Any help is appreciated.