This is my directory structure, in /var/www
:
team_django
--team_db
---- __init__.py
-----settings.py
-----wsgi.py
My wsgi.py:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'team_db.settings')
application = get_wsgi_application()
My /etc/apache2/mods-available/wsgi.load
:
LoadModule wsgi_module "/usr/local/py_ptracker/lib/python3.11/site-packages/mod_wsgi/server/mod_wsgi-py311.cpython-311-x86_64-linux-gnu.so"
WSGIPythonHome "/usr/local/py_ptracker"
My /etc/apache2/sites-available/vhost.conf
:
<VirtualHost *:80>
ServerName mydomain
WSGIScriptAlias / /var/www/team_django/team_db/wsgi.py
<Directory /var/www/team_django/team_db>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
The mod_wsgi
is enabled, as the vhost configuration, and everything gets loaded fine. I get this in the error.log
though:
ModuleNotFoundError: No module named 'team_db'
[wsgi:error] [pid 225277] mod_wsgi (pid=225277): Failed to exec Python script file '/var/www/team_django/team_db/wsgi.py'., referer: ...
[wsgi:error] [pid 225277] mod_wsgi (pid=225277): Exception occurred processing WSGI script '/var/www/team_django/team_db/wsgi.py'., referer: ....
Why isn't the os.environ.setdefault
finding team_db
? I've checked all permisions and I also set everything to 777, changing owners and group to www-data or root and all that; to no avail. I can't understand why it's not finding the team_db. Te server runs correctly with Django's runserver and also with the mod_wsgi-express runserver.
The mod_wsgi has been built with the same version of Python, within the virtual environment.
I had to add
from django.core.wsgi import get_wsgi_application
sys.path.append('/var/www/')
sys.path.append('/var/www/team_django')
sys.path.append('/var/www/team_django/team_db')```
to my .wsgi