I'm trying to deploy a django project with the following Apache configuration:
Apache virtualhost configuration
<Virtualhost *:80>
DocumentRoot /var/www/project/backend
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIDaemonProcess backend python-home=/var/www/project/myenv python-path=/var/www/gestor_documental/backend
WSGIProcessGroup backend
WSGIScriptAlias / /var/www/project/backend/backend/wsgi.py process-group=backend
Alias /static/ /var/www/project/backend/static/
<Directory /var/www/project/backend>
Require all granted
</Directory>
</Virtualhost>
wsgi.load file
LoadModule wsgi_module "/var/www/project/myenv/lib/python3.5/site-packages/mod_wsgi/server/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so"
WSGIPythonHome "/var/www/project/myenv"
The wsgi.py is the one django brings by default
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")
application = get_wsgi_application()
This is the project tree:
project
|- backend
| |- api (django app)
| |- backend
| |- ...
| |- settings.py
| |- wsgi.py
|-- myenv (virtualenv)
And this is the error log I keep getting when i try to load the web:
mod_wsgi (pid=38953): Failed to exec Python script file '/var/www/project/backend/backend/wsgi.py'.
mod_wsgi (pid=38953): Exception occurred processing WSGI script '/var/www/project/backend/backend/wsgi.py'.
Traceback (most recent call last):
File "/var/www/project/backend/backend/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/var/www/project/myenv/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/var/www/project/myenv/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/var/www/project/myenv/lib/python3.5/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/var/www/project/myenv/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/var/www/project/myenv/lib/python3.5/site-packages/django/conf/__init__.py", line 97, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/var/www/project/myenv/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'backend'
I've followed every single tutorial and try tons of configurations but still getting the same error.
I'm using python 3.5.2 in a virtualenv and Apache 2.4.18
I've installed mod_wsgi via pip3.
Could someone help me with this and tell me what am i doing wrong?
Thank you.
backendsomewhere in your files? Is backend only a folder or also a file? Because you're trying to import the modulebackendsomewhere and it cannot find a module that's calledbackend.backendis the name of my project's folder and i didn't import it anywherewsgi.py?wsgi.pyis the one django brings by default. I actually don't know what that file does. I'm going to edit the post and put the file so you can see what it has inside.backend/settings.py? Thepython-pathshould include the parent directory of thatbackenddirectory in that path.