Can't get Django-CMS to work with Apache and mod_wsgi
I am trying to get django-cms to run with apache wsgi. I am using Python 3.12 and the latest version of all software (a fresh bare metal install of ubuntu 24.04). Django-cms runs with runserver.
My vhost file
:
Define impact_lab_partners_path /home/mark/python-projects/impact_lab_partners
WSGIApplicationGroup %{GLOBAL}
<VirtualHost *:80>
ServerName impactlabpartners.com
ServerAlias www.impactlabpartners.com
ServerAdmin xxxxxxxxxxxxxxxxx
DocumentRoot /home/mark/python-projects/impact_lab_partners
ProxyRequests off
ProxyPreserveHost On
WSGIDaemonProcess ilp python-home=/home/mark/.virtualenvs/impact_lab_partners python-path=${impact_lab_partners_path}/impact_lab_partners
WSGIProcessGroup ilp
WSGIScriptAlias / ${impact_lab_partners_path}/impact_lab_parthers/wsgi.py process-group=ilp
Alias /static "/home/mark/Documents/impact_lab_partners/do_not_change/static"
<Directory "/home/mark/Documents/impact_lab_partners/do_not_change/static">
Require all granted
</Directory>
Alias /documents "/home/mark/Documents/impact_lab_partners/do_not_change/documents"
<Directory "/home/mark/Documents/impact_lab_partners/do_not_change/documents">
Require all granted
</Directory>
<Directory ${impact_lab_partners_path}/impact_lab_partners>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
# LogLevel Debug
# LogLevel debug
# ErrorLog ${APACHE_LOG_DIR}/impact_lab_partners/error.log
# CustomLog ${APACHE_LOG_DIR}/impact_lab_partners/access.log combined
</VirtualHost>
I have verified the paths are correct.
The error I am getting in /var/log/apache2/error.log
every second or so:
Current thread 0x0000731f722d1780 (most recent call first):
<no Python frame>
[Thu Dec 05 18:27:05.634492 2024] [wsgi:warn] [pid 21694:tid 126578896738176] (13)Permission denied: mod_wsgi (pid=21694): Unable to stat Python home /home/mark/.virtualenvs/impact_lab_partners. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path.
Python path configuration:
PYTHONHOME = '/home/mark/.virtualenvs/impact_lab_partners'
PYTHONPATH = (not set)
program name = 'python3'
isolated = 0
environment = 1
user site = 1
safe_path = 0
import site = 1
is in build tree = 0
stdlib dir = '/home/mark/.virtualenvs/impact_lab_partners/lib/python3.12'
sys._base_executable = '/usr/bin/python3'
sys.base_prefix = '/home/mark/.virtualenvs/impact_lab_partners'
sys.base_exec_prefix = '/home/mark/.virtualenvs/impact_lab_partners'
sys.platlibdir = 'lib'
sys.executable = '/usr/bin/python3'
sys.prefix = '/home/mark/.virtualenvs/impact_lab_partners'
sys.exec_prefix = '/home/mark/.virtualenvs/impact_lab_partners'
sys.path = [
'/home/mark/.virtualenvs/impact_lab_partners/lib/python312.zip',
'/home/mark/.virtualenvs/impact_lab_partners/lib/python3.12',
'/home/mark/.virtualenvs/impact_lab_partners/lib/python3.12/lib-dynload',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
I tried googling for the missing module 'encodings' and nothing I found helped. I don't understand why the Python Path is not set. I have tried all sorts of paths for the python-home and python path values, but nothing seems to work.
After further troubleshooting, I discovered there was a mispelled path statement in the apache3 .conf file. However, the real culprit seems to be that Ubuntu 22.04 changed the default permission for /home/user folders from 755 to 750. When I changed the /home/mark folder to 755, the site worked.