I am getting the following error. I tried the other answers provided for the same error but nothing is working. Any help would be appreciated.
Apache error log:
[Thu Aug 10 19:51:22.397653 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] mod_wsgi (pid=10908): Target WSGI script '/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py' cannot be loaded as Python module.
[Thu Aug 10 19:51:22.397731 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] mod_wsgi (pid=10908): Exception occurred processing WSGI script '/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py'.
[Thu Aug 10 19:51:22.398589 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] Traceback (most recent call last):
[Thu Aug 10 19:51:22.398657 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py", line 16, in <module>
[Thu Aug 10 19:51:22.398664 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] application = get_wsgi_application()
[Thu Aug 10 19:51:22.398675 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Thu Aug 10 19:51:22.398680 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] django.setup(set_prefix=False)
[Thu Aug 10 19:51:22.398689 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
[Thu Aug 10 19:51:22.398694 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Thu Aug 10 19:51:22.398703 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages/django/conf/__init__.py", line 56, in __getattr__
[Thu Aug 10 19:51:22.398708 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] self._setup(name)
[Thu Aug 10 19:51:22.398717 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
[Thu Aug 10 19:51:22.398722 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] self._wrapped = Settings(settings_module)
[Thu Aug 10 19:51:22.398731 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages/django/conf/__init__.py", line 110, in __init__
[Thu Aug 10 19:51:22.398736 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] mod = importlib.import_module(self.SETTINGS_MODULE)
[Thu Aug 10 19:51:22.398745 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "/home/sharan/myproject/myprojectenv/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Thu Aug 10 19:51:22.398749 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] return _bootstrap._gcd_import(name[level:], package, level)
[Thu Aug 10 19:51:22.398758 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Thu Aug 10 19:51:22.398776 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Thu Aug 10 19:51:22.398786 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
[Thu Aug 10 19:51:22.398795 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Thu Aug 10 19:51:22.398864 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Thu Aug 10 19:51:22.398879 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Thu Aug 10 19:51:22.398889 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
[Thu Aug 10 19:51:22.398913 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] ImportError: No module named 'proj_VivRx1'
Virtualhost file (apache2/sites-available/000-default.conf)
ServerAdmin webmaster#localhost
DocumentRoot /home/sharan/myproject
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/sharan/myproject/proj_VivRx1/app_match/static
<Directory /home/sharan/myproject/proj_VivRx1/app_match/static>
Require all granted
</Directory>
<Directory /home/sharan/myproject/proj_VivRx1/proj_VivRx1>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /home/sharan/myproject/proj_VivRx1/proj_VivRx1>
Require all granted
</Directory>
<Directory /home/sharan/myproject/proj_VivRx1>
Require all granted
</Directory>
<Directory /home/sharan/myproject/myprojectenv>
Require all granted
</Directory>
WSGIDaemonProcess myproject python-path=/home/sharan/myprojects python-home=/home/sharan/myproject/myprojectenv
WSGIProcessGroup myproject
WSGIScriptAlias / /home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py
WSGI file (/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py):
import os,sys
sys.path.append('/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages')
sys.path.append('/home/sharan/myproject/proj_VivRx1')
from django.core.wsgi import get_wsgi_application
path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if path not in sys.path:
sys.path.append(path)
os.environ["DJANGO_SETTINGS_MODULE"] = "{{ project_name }}.settings"
application = get_wsgi_application()
I have tried playing around with locations. Also checked the permissions but to no use. Apache version is 2.4.18.
You should add your project path (/home/sharan/myproject/proj_VivRx1) to python-path parameter of WSGIDaemonProcess Apache directive.
*
[Thu Aug 10 19:51:22.397653 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] mod_wsgi (pid=10908): Target WSGI script '/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py' cannot be loaded as Python module.
[Thu Aug 10 19:51:22.397731 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] mod_wsgi (pid=10908): Exception occurred processing WSGI script '/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py'.
[Thu Aug 10 19:51:22.398589 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] Traceback (most recent call last):
Your directory structure is messed up. You have a mixmatch of directories where your wsgi file is located, is it in /home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py as the virtual host is setup to look for it... or is it /home/sharan/myproject/proj_VivRx1/wsgi.py?
You most likely need to adjust your folder paths to point to the right location where your wsgi file is located.
Related
I want to serve my project using mod_wsgi. When i run development server, It's started but it gives error on production server.My os is RedHat and using httpd(apache) virtual host configured with python3-mod_wsgi.
This is my error
[Tue Oct 05 14:01:48.998236 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] mod_wsgi (pid=423542): Failed to exec Python script file '/var/www/public_html/main/main/wsgi.py'.
[Tue Oct 05 14:01:48.998291 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] mod_wsgi (pid=423542): Exception occurred processing WSGI script '/var/www/public_html/main/main/wsgi.py'.
[Tue Oct 05 14:01:48.998461 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] Traceback (most recent call last):
[Tue Oct 05 14:01:48.998506 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "/var/www/public_html/main/main/wsgi.py", line 17, in <module>
[Tue Oct 05 14:01:48.998523 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] application = get_wsgi_application()
[Tue Oct 05 14:01:48.998530 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "/usr/local/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Tue Oct 05 14:01:48.998534 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] django.setup(set_prefix=False)
[Tue Oct 05 14:01:48.998540 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
[Tue Oct 05 14:01:48.998543 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Tue Oct 05 14:01:48.998548 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 76, in __getattr__
[Tue Oct 05 14:01:48.998552 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] self._setup(name)
[Tue Oct 05 14:01:48.998557 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 63, in _setup
[Tue Oct 05 14:01:48.998560 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] self._wrapped = Settings(settings_module)
[Tue Oct 05 14:01:48.998565 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 142, in __init__
[Tue Oct 05 14:01:48.998569 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] mod = importlib.import_module(self.SETTINGS_MODULE)
[Tue Oct 05 14:01:48.998574 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
[Tue Oct 05 14:01:48.998577 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] return _bootstrap._gcd_import(name[level:], package, level)
[Tue Oct 05 14:01:48.998582 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Tue Oct 05 14:01:48.998587 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Tue Oct 05 14:01:48.998592 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
[Tue Oct 05 14:01:48.998597 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[Tue Oct 05 14:01:48.998602 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Tue Oct 05 14:01:48.998614 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Tue Oct 05 14:01:48.998619 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[Tue Oct 05 14:01:48.998633 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] ModuleNotFoundError: No module named 'main'
This is my project wsgi.py file
import os
import sys
#from django.conf import settings
from django.core.wsgi import get_wsgi_application
#sys.path.append('/var/www/public_html/main/')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings')
application = get_wsgi_application()
I Changed my wsgi.py file to this now it's working
"""
WSGI config for main project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
"""
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('/var/www/public_html/')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings')
application = get_wsgi_application()
we are trying to run django3 (python3.6 on Centos7) with httpd.
i get following error when i run it by HTTPD.
[Tue Jan 12 06:52:04.575618 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] Traceback (most recent call last):
[Tue Jan 12 06:52:04.575665 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "/srv/django/django/wsgi.py", line 16, in <module>
[Tue Jan 12 06:52:04.575670 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] application=get_wsgi_application()
[Tue Jan 12 06:52:04.575678 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "/usr/local/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Tue Jan 12 06:52:04.575682 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] django.setup(set_prefix=False)
[Tue Jan 12 06:52:04.575690 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
[Tue Jan 12 06:52:04.575694 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Tue Jan 12 06:52:04.575701 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 82, in __getattr__
[Tue Jan 12 06:52:04.575706 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] self._setup(name)
[Tue Jan 12 06:52:04.575713 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 69, in _setup
[Tue Jan 12 06:52:04.575717 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] self._wrapped = Settings(settings_module)
[Tue Jan 12 06:52:04.575724 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 170, in __init__
[Tue Jan 12 06:52:04.575729 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] mod = importlib.import_module(self.SETTINGS_MODULE)
[Tue Jan 12 06:52:04.575736 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
[Tue Jan 12 06:52:04.575740 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] return _bootstrap._gcd_import(name[level:], package, level)
[Tue Jan 12 06:52:04.575747 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Tue Jan 12 06:52:04.575755 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Tue Jan 12 06:52:04.575762 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[Tue Jan 12 06:52:04.575780 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] ModuleNotFoundError: No module named 'django.settings'```
my django.conf file in /etc/httpd/conf.d is as follows:
Alias /static /srv/static
<Directory /srv/static>
Require all granted
</Directory>
<Directory /srv/django/django>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess django python-path=/srv/django:/usr/local/lib/python3.6/site-packages
WSGIProcessGroup django
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /srv/django/django/wsgi.py
and my wsgi.py as as follows:
import os
import sys
from django.core.wsgi import get_wsgi_application
os.chdir('/srv/django/')
sys.path.append('/srv/django/')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django.settings')
application=get_wsgi_application()
we installed following packages
python3-devel.x86_64
rh-python36-mod_wsgi.x86_64
yum install httpd-devel
django project as such is working fine
100.10.100.10 (/srv/django/)-1003> python3 manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
January 12, 2021 - 05:22:31
Django version 3.1.5, using settings 'django.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
what am i missing?
I am not too familiar on how well Apache Httpd works with WSGI, but if you're starting Django separately and you simply want to a reverse proxy up an running quickly you could do the following:
<VirtualHost *:80>
ServerAdmin admin#localhost
ProxyRequests off
DocumentRoot /var/www
# SSLProxyEngine on
# ProxyPreserveHost On
ServerName www.yoursite.net
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel error
<Location />
ProxyPass http://www.yourwebsite.net/
ProxyPassReverse http://localhost:8080/
Order allow,deny
Allow from all
</Location>
</VirtualHost>
In terms of the error, it looks like wsgi.py can't find django.settings meaning the django directory and settings module aren't in the current path.
I am trying to host a Django website on an Ubuntu VPS with Apache/mod_wsgi.
If I run it in embedded mode, the site loads.
WSGIScriptAlias / /home/admin/web/mywebsite/myproject/wsgi.py
WSGIPythonHome /home/admin/web/mywebsite/venv
WSGIPythonPath /home/admin/web/mywebsite
<Directory /home/admin/web/mywebsite/myproject>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
However, if I try to run it in daemon mode, I get an error: ModuleNotFoundError: No module named 'myproject'.
WSGIDaemonProcess myproject python-home=/home/admin/web/mywebsite/venv python-path=/home/admin/web/mywebsite socket-user=#1001
WSGIProcessGroup myproject
WSGIScriptAlias / /home/admin/web/mywebsite/myproject/wsgi.py
My WSGI file:
import os
from django.core.wsgi import get_wsgi_application
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
application = get_wsgi_application()
If I run a manage.py command, it shows the same ModuleNotFoundError error in both embedded and daemon mode. What could possibly be wrong?
[Mon Feb 24 09:00:37.333725 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] mod_wsgi (pid=7830): Target WSGI script '/home/admin/web/mywebsite/myproject/wsgi.py' cannot be loaded as Python module.
[Mon Feb 24 09:00:37.333768 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] mod_wsgi (pid=7830): Exception occurred processing WSGI script '/home/admin/web/mywebsite/myproject/wsgi.py'.
[Mon Feb 24 09:00:37.334090 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] Traceback (most recent call last):
[Mon Feb 24 09:00:37.334124 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] File "/home/admin/web/mywebsite/myproject/wsgi.py", line 16, in <module>
[Mon Feb 24 09:00:37.334127 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] application = get_wsgi_application()
[Mon Feb 24 09:00:37.334131 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] File "/home/admin/web/mywebsite/venv/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Mon Feb 24 09:00:37.334133 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] django.setup(set_prefix=False)
[Mon Feb 24 09:00:37.334136 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] File "/home/admin/web/mywebsite/venv/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
[Mon Feb 24 09:00:37.334139 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Mon Feb 24 09:00:37.334142 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] File "/home/admin/web/mywebsite/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 76, in __getattr__
[Mon Feb 24 09:00:37.334144 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] self._setup(name)
[Mon Feb 24 09:00:37.334147 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] File "/home/admin/web/mywebsite/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 63, in _setup
[Mon Feb 24 09:00:37.334149 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] self._wrapped = Settings(settings_module)
[Mon Feb 24 09:00:37.334152 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] File "/home/admin/web/mywebsite/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 142, in __init__
[Mon Feb 24 09:00:37.334154 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] mod = importlib.import_module(self.SETTINGS_MODULE)
[Mon Feb 24 09:00:37.334157 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
[Mon Feb 24 09:00:37.334159 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] return _bootstrap._gcd_import(name[level:], package, level)
[Mon Feb 24 09:00:37.334162 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Mon Feb 24 09:00:37.334165 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Mon Feb 24 09:00:37.334169 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
[Mon Feb 24 09:00:37.334172 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[Mon Feb 24 09:00:37.334175 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Mon Feb 24 09:00:37.334178 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Mon Feb 24 09:00:37.334188 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[Mon Feb 24 09:00:37.334197 2020] [wsgi:error] [pid 7830] [remote 5.187.171.36:18335] ModuleNotFoundError: No module named 'myproject'
I am struggling trying to get Apache 2.4.7 to serve a Django 1.8.17 application using mod_wsgi 4.5.15 with Python 3.5.3 as a virtual environment. This is the only virtual environment I have on the machine (Linux Mint 17.3).
I am getting an "internal Server Error" in the browser.
My Apache error log says:
[Thu Apr 06 19:48:22.530935 2017] [mpm_prefork:notice] [pid 4476] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.21 mod_wsgi/4.5.15 Python/3.5 configured -- resuming normal operations
[Thu Apr 06 19:48:22.531008 2017] [core:notice] [pid 4476] AH00094: Command line: '/usr/sbin/apache2'
[Thu Apr 06 19:48:28.165360 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] mod_wsgi (pid=4480): Target WSGI script '/home/magic-rat/ektropy_project/ektropy_project/wsgi.py' cannot be loaded as Python module.
[Thu Apr 06 19:48:28.165494 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] mod_wsgi (pid=4480): Exception occurred processing WSGI script '/home/magic-rat/ektropy_project/ektropy_project/wsgi.py'.
[Thu Apr 06 19:48:28.166150 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] Traceback (most recent call last):
[Thu Apr 06 19:48:28.166210 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/ektropy_project/ektropy_project/wsgi.py", line 16, in <module>
[Thu Apr 06 19:48:28.166218 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] application = get_wsgi_application()
[Thu Apr 06 19:48:28.166230 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/virtualenvs/ektropy_project/lib/python3.5/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Thu Apr 06 19:48:28.166238 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] django.setup()
[Thu Apr 06 19:48:28.166250 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/virtualenvs/ektropy_project/lib/python3.5/site-packages/django/__init__.py", line 17, in setup
[Thu Apr 06 19:48:28.166257 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Thu Apr 06 19:48:28.166269 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/virtualenvs/ektropy_project/lib/python3.5/site-packages/django/conf/__init__.py", line 48, in __getattr__
[Thu Apr 06 19:48:28.166276 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] self._setup(name)
[Thu Apr 06 19:48:28.166288 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/virtualenvs/ektropy_project/lib/python3.5/site-packages/django/conf/__init__.py", line 44, in _setup
[Thu Apr 06 19:48:28.166295 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] self._wrapped = Settings(settings_module)
[Thu Apr 06 19:48:28.166307 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/virtualenvs/ektropy_project/lib/python3.5/site-packages/django/conf/__init__.py", line 92, in __init__
[Thu Apr 06 19:48:28.166314 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] mod = importlib.import_module(self.SETTINGS_MODULE)
[Thu Apr 06 19:48:28.166325 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/usr/local/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Thu Apr 06 19:48:28.166335 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] return _bootstrap._gcd_import(name[level:], package, level)
[Thu Apr 06 19:48:28.166347 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Thu Apr 06 19:48:28.166358 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Thu Apr 06 19:48:28.166369 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
[Thu Apr 06 19:48:28.166381 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Thu Apr 06 19:48:28.166392 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Thu Apr 06 19:48:28.166418 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Thu Apr 06 19:48:28.166429 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
[Thu Apr 06 19:48:28.166464 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] ImportError: No module named 'ektropy_project'
My directory structure is:
home/magic-rat/
|
|__________virtualenvs
| |
| |-ektropy_project
| |
| |-lib
| |
| |-python3.5
| |
| |-site_packages
|
|__________ektropy_project
|
|-manage.py
|
|-ektropy_project
|
|-wsgi.py
|-helloworld.wsgi (so you can see where it is)
My Apache Virtual host file is:
<VirtualHost *:8000>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
WSGIDaemonProcess ektropy_project python-home=/home/magic-rat/virtualenvs/ektropy_project
WSGIProcessGroup ektropy_project
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /home/magic-rat/ektropy_project/ektropy_project/wsgi.py
<Directory /home/magic-rat/ektropy_project/ektropy_project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
My wsgi.py file is:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ektropy_project.settings")
application = get_wsgi_application()
I believe mod_wsgi is configured properly. I can run a simple hello_world program and it works.
I believe permissions are set properly on all the files.
Any help is appreciated.
Add an extra option to WSGIDaemonProcess of:
python-path=/home/magic-rat/ektropy_project
You have to tell mod_wsgi where your project code is as well so it can import it.
I keep receiving this error in the apache error.log when I visit the URL for this project:
[Fri Jan 20 21:04:16.143990 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] mod_wsgi (pid=18618): Target WSGI script '/srv/botbot/src/botbot/botbot/wsgi.py' cannot be loaded as Python module.
[Fri Jan 20 21:04:16.144124 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] mod_wsgi (pid=18618): Exception occurred processing WSGI script '/srv/botbot/src/botbot/botbot/wsgi.py'.
[Fri Jan 20 21:04:16.144195 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] Traceback (most recent call last):
[Fri Jan 20 21:04:16.144255 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] File "/srv/botbot/src/botbot/botbot/wsgi.py", line 9, in <module>
[Fri Jan 20 21:04:16.144335 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] application = get_wsgi_application()
[Fri Jan 20 21:04:16.144381 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] File "/srv/botbot/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Fri Jan 20 21:04:16.144437 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] django.setup()
[Fri Jan 20 21:04:16.144487 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] File "/srv/botbot/lib/python2.7/site-packages/django/__init__.py", line 17, in setup
[Fri Jan 20 21:04:16.144540 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Fri Jan 20 21:04:16.144586 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] File "/srv/botbot/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
[Fri Jan 20 21:04:16.144638 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] self._setup(name)
[Fri Jan 20 21:04:16.144675 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] File "/srv/botbot/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
[Fri Jan 20 21:04:16.144711 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] self._wrapped = Settings(settings_module)
[Fri Jan 20 21:04:16.144747 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] File "/srv/botbot/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__
[Fri Jan 20 21:04:16.144793 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] mod = importlib.import_module(self.SETTINGS_MODULE)
[Fri Jan 20 21:04:16.144822 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Fri Jan 20 21:04:16.144856 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] __import__(name)
[Fri Jan 20 21:04:16.144884 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] File "/srv/botbot/src/botbot/botbot/settings/__init__.py", line 1, in <module>
[Fri Jan 20 21:04:16.144930 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] from base import *
[Fri Jan 20 21:04:16.145008 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] File "/srv/botbot/src/botbot/botbot/settings/base.py", line 27, in <module>
[Fri Jan 20 21:04:16.145053 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] SECRET_KEY = os.environ['WEB_SECRET_KEY']
[Fri Jan 20 21:04:16.145085 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
[Fri Jan 20 21:04:16.145118 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] raise KeyError(key)
[Fri Jan 20 21:04:16.145157 2017] [:error] [pid 18618:tid 140192977487616] [remote 66.90.146.30:326] KeyError: 'WEB_SECRET_KEY'
This is my wsgi.py file:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "botbot.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
This is my .env file:
# Required
SECRET_KEY='password1'
WEB_PORT=8000
EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend'
GOPATH=$VIRTUAL_ENV
WEB_SECRET_KEY='password1'
STORAGE_URL=postgres://ubuntu:password#localhost:5432/botbot
REDIS_PLUGIN_STORAGE_URL=redis://localhost:6379/0
REDIS_PLUGIN_QUEUE_URL=redis://localhost:6379/1
PUSH_STREAM_URL=http://localhost:8080/pub/?id={id}
# Set encoding if the system hasn't done it properly
LANG=en_US.UTF-8
PYTHONIOENCODING=utf8
# Optional
# MEMCACHE_URL=127.0.0.1:11211
# STATIC_ROOT=/var/www/botbot/static
# MEDIA_ROOT=/var/www/botbot/uploads
# DEBUG=True
# SMTP_URL=smtp://user:pass#host:port
# SMTP_TLS=True
# ALLOWED_HOSTS=host1,host2
# INCLUDE_DJANGO_ADMIN=False
# EXCLUDE_NICKS=nick1,nick2
This is my apache conf file:
<VirtualHost *:80>
ServerName server.test.com
ErrorLog ${APACHE_LOG_DIR}/error.log
SetEnv WEB_SECRET_KEY password1
CustomLog ${APACHE_LOG_DIR}/access.log combined
DocumentRoot /srv/botbot/src/botbot
<Directory /srv/botbot/src/botbot/botbot>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess botbot python-path=/srv/botbot/src/botbot/botbot:/srv/botbot/lib/python2.7/site-packages
WSGIProcessGroup botbot
WSGIScriptAlias / /srv/botbot/src/botbot/botbot/wsgi.py
</VirtualHost>
This is the app I'm trying to build: https://github.com/BotBotMe/botbot-web.
As you can see I've tried setting the SetEnv variable in the apache conf but with no luck. I'm not even sure if that's the right thing to be doing, no matter what I do I still receive the error below.
I believe that you should try SetEnvIf directive, as reading in apache docs:
The internal environment variables set by this directive are set after
most early request processing directives are run, such as access
control and URI-to-filename mapping. If the environment variable you're
setting is meant as input into this early phase of processing such as
the RewriteRule directive, you should instead set the environment
variable with SetEnvIf.
Probably if you want to set it by SetEnv - it is just not available for the django app when starting yet.
But probably the best thing you can do - is to set this env variable in some pre-run script.
Happy coding!
I ended up adding the following line to my wsgi.py file:
os.environ['WEB_SECRET_KEY'] = 'password'
where 'password' is equal to the password string specified in the .env file for the WEB_SECRET_KEY variable.
I also had to recursively chown the /srv directory (which contains the app and nothing else) to the www-data user.
This document was helpful: https://gist.github.com/GrahamDumpleton/b380652b768e81a7f60c