Django won't run on Apache with mod_wsgi - python

I'm trying to get Django 2.2 to run on Apache 2.4 with Python 3.7 on a Windows 2016 Server. Django runs fine on the development server (manage.py runserver) and the Apache Server runs and is reachable on the network but Django doesn't run on Apache. This is the Apache config (httpd.conf) I'm running:
ServerName localhost:80
<Directory />
AllowOverride none
Require all denied
</Directory>
LoadFile "c:/program files/python37/python37.dll"
LoadModule wsgi_module "c:/program files/python37/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "c:/program files/python37"
WSGIScriptAlias \ "D:\Django\myproject\myproject\wsgi.py"
WSGIPythonPath "D:\Django\myproject\myproject"
<Directory "D:\Django\myproject\myproject">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
DocumentRoot "${SRVROOT}/htdocs"
<Directory "${SRVROOT}/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
Here's my wsgi.py (not changed from what was generated during manage.py startproject):
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
application = get_wsgi_application()
When I try to load http://myserver in the browser, I get the Apache Defualt page, but If I try to load http://myserver:8000 I get a connection error.
Edit:
Here are the relevant entries of error.log:
[Fri Feb 08 11:30:15.853857 2019] [wsgi:info] [pid 864:tid 436] mod_wsgi (pid=864): Python home c:/program files/python37.
[Fri Feb 08 11:30:15.853857 2019] [wsgi:info] [pid 864:tid 436] mod_wsgi (pid=864): Initializing Python.
[Fri Feb 08 11:30:15.869484 2019] [wsgi:info] [pid 864:tid 436] mod_wsgi (pid=864): Attach interpreter ''.
[Fri Feb 08 11:30:15.885109 2019] [wsgi:info] [pid 864:tid 436] mod_wsgi (pid=864): Adding 'D:\\Django\\myproject\\myproject' to path.
[Fri Feb 08 11:30:15.885109 2019] [wsgi:info] [pid 864:tid 436] mod_wsgi (pid=864): Imported 'mod_wsgi'.
Looks like it loads fine, but it doesn't even try to listen on port 8000.
Edit2:
So my setting for WSGIScriptAlias seems to have been wrong. Now it's at least trying to load the WSGI app.
[Fri Feb 08 12:28:02.123312 2019] [wsgi:info] [pid 856:tid 1212] mod_wsgi (pid=856): Create interpreter 'localhost|/test'.
[Fri Feb 08 12:28:02.138940 2019] [wsgi:info] [pid 856:tid 1212] mod_wsgi (pid=856): Adding 'D:\\Django\\kte_test\\kte_test' to path.
[Fri Feb 08 12:28:02.138940 2019] [wsgi:info] [pid 856:tid 1212] [client 172.16.27.254:51858] mod_wsgi (pid=856, process='', application='localhost|/test'): Loading Python script file 'D:/Django/kte_test/kte_test/wsgi.py'.
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] mod_wsgi (pid=856): Failed to exec Python script file 'D:/Django/kte_test/kte_test/wsgi.py'.
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] mod_wsgi (pid=856): Exception occurred processing WSGI script 'D:/Django/kte_test/kte_test/wsgi.py'.
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] Traceback (most recent call last):\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] File "D:/Django/kte_test/kte_test/wsgi.py", line 16, in <module>\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] application = get_wsgi_application()\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] File "c:\\program files\\python37\\lib\\site-packages\\django\\core\\wsgi.py", line 12, in get_wsgi_application\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] django.setup(set_prefix=False)\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] File "c:\\program files\\python37\\lib\\site-packages\\django\\__init__.py", line 19, in setup\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] File "c:\\program files\\python37\\lib\\site-packages\\django\\conf\\__init__.py", line 57, in __getattr__\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] self._setup(name)\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] File "c:\\program files\\python37\\lib\\site-packages\\django\\conf\\__init__.py", line 44, in _setup\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] self._wrapped = Settings(settings_module)\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] File "c:\\program files\\python37\\lib\\site-packages\\django\\conf\\__init__.py", line 107, in __init__\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] mod = importlib.import_module(self.SETTINGS_MODULE)\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] File "c:\\program files\\python37\\lib\\importlib\\__init__.py", line 127, in import_module\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] return _bootstrap._gcd_import(name[level:], package, level)\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] File "<frozen importlib._bootstrap>", line 1006, in _gcd_import\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] File "<frozen importlib._bootstrap>", line 983, in _find_and_load\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] File "<frozen importlib._bootstrap>", line 1006, in _gcd_import\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] File "<frozen importlib._bootstrap>", line 983, in _find_and_load\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] ModuleNotFoundError: No module named 'myproject'\r
Where do I find the missing module?

Related

Hosting Django in Apache

I try to host Django at Apache using mod_wsgi and following a nice tutorial. I have a Windows 7 OP, and I had everything set as described by the tutorial, however, I get this Error 500 for which I paste the ErrorLogs below:
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] mod_wsgi (pid=7784): Failed to exec Python script file 'D:/Backup/Learning Python/Organized and important file/Learning files and sheets/Django_ Learning_ 1/weblog_app/weblog_app/wsgi.py'.
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] mod_wsgi (pid=7784): Exception occurred processing WSGI script 'D:/Backup/Learning Python/Organized and important file/Learning files and sheets/Django_ Learning_ 1/weblog_app/weblog_app/wsgi.py'.
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] Traceback (most recent call last):\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] File "D:/Backup/Learning Python/Organized and important file/Learning files and sheets/Django_ Learning_ 1/weblog_app/weblog_app/wsgi.py", line 16, in <module>\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] application = get_wsgi_application()\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] File "c:\\users\\adwy\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\django\\core\\wsgi.py", line 12, in get_wsgi_application\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] django.setup(set_prefix=False)\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] File "c:\\users\\adwy\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\django\\__init__.py", line 19, in setup\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] File "c:\\users\\adwy\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\django\\conf\\__init__.py", line 79, in __getattr__\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] self._setup(name)\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] File "c:\\users\\adwy\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\django\\conf\\__init__.py", line 66, in _setup\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] self._wrapped = Settings(settings_module)\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] File "c:\\users\\adwy\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\django\\conf\\__init__.py", line 157, in __init__\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] mod = importlib.import_module(self.SETTINGS_MODULE)\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] File "c:\\users\\adwy\\appdata\\local\\programs\\python\\python35\\lib\\importlib\\__init__.py", line 126, in import_module\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] return _bootstrap._gcd_import(name[level:], package, level)\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] File "<frozen importlib._bootstrap>", line 986, in _gcd_import\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] File "<frozen importlib._bootstrap>", line 969, in _find_and_load\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] File "<frozen importlib._bootstrap>", line 986, in _gcd_import\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] File "<frozen importlib._bootstrap>", line 969, in _find_and_load\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked\r
[Mon Apr 06 14:37:28.669698 2020] [wsgi:error] [pid 7784:tid 1048] [client 95.47.51.217:48374] ImportError: No module named 'weblog_app'\r
basically, I don't know if the problem is in the mod_wsgi version that I'm using or in the CONFIG that I used:
here I copy the CONFIG that I used for Apache
LoadModule wsgi_module "c:/users/adwy/appdata/local/programs/python/python35/lib/site-packages/mod_wsgi/server/mod_wsgi.cp35-win_amd64.pyd"
WSGIScriptAlias / "D:/Backup/Learning Python/Organized and important file/Learning files and sheets/Django_ Learning_ 1/weblog_app/weblog_app/wsgi.py"
WSGIPythonHome "c:/users/adwy/appdata/local/programs/python/python35"
WSGIPythonPath "D:/Backup/Learning Python/Organized and important file/Learning files and sheets/Django_ Learning_ 1/weblog_app/weblog_app"
Alias "/static/" "C:/Users/Adwy/Adwy/Django_ Learning_ 1/Lib/site-packages/django/contrib/admin/static"
Alias "/templates/" "C:/Users/Adwy/Adwy/Django_ Learning_ 1/Lib/site-packages/django/contrib/admin/templates"
<Directory "C:/Users/Adwy/Adwy/Django_ Learning_ 1/Lib/site-packages/django/contrib/admin/static">
Require all granted
</Directory>
<Directory "C:/Users/Adwy/Adwy/Django_ Learning_ 1/Lib/site-packages/django/contrib/admin/templates">
Require all granted
</Directory>
<Directory "D:/Backup/Learning Python/Organized and important file/Learning files and sheets/Django_ Learning_ 1/weblog_app/weblog_app">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Can anybody with some experience here help me,
thanks alot,

Permission denied when importing paramiko from flask app -apache wsgi mod

I've been trying to deploy my flask app using apache as a server(wsgi_mod). I created all the necessary files (.wsgi and .conf file for apache).
But when i request the page i get a 500 error. Checking the logs shows a
[Fri Jul 05 12:39:18.746453 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] mod_wsgi (pid=74305): Target WSGI script '/var/www/html/ExampleFlask/ExampleFlask/my_flask_app.wsgi' cannot be loaded as Python module.
[Fri Jul 05 12:39:18.746912 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] mod_wsgi (pid=74305): Exception occurred processing WSGI script '/var/www/html/ExampleFlask/ExampleFlask/my_flask_app.wsgi'.
[Fri Jul 05 12:39:18.750486 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] Traceback (most recent call last):
[Fri Jul 05 12:39:18.750808 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] File "/var/www/html/ExampleFlask/ExampleFlask/my_flask_app.wsgi", line 6, in <module>
[Fri Jul 05 12:39:18.750995 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] from my_flask_app import app as application
[Fri Jul 05 12:39:18.751224 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] File "/var/www/html/ExampleFlask/ExampleFlask/my_flask_app.py", line 2, in <module>
[Fri Jul 05 12:39:18.751411 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] import paramiko
[Fri Jul 05 12:39:18.751600 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] File "/usr/lib/python3/dist-packages/paramiko/__init__.py", line 30, in <module>
[Fri Jul 05 12:39:18.751819 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] from paramiko.transport import SecurityOptions, Transport
[Fri Jul 05 12:39:18.752023 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] File "/usr/lib/python3/dist-packages/paramiko/transport.py", line 32, in <module>
[Fri Jul 05 12:39:18.752224 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] from cryptography.hazmat.backends import default_backend
[Fri Jul 05 12:39:18.752446 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] File "/usr/lib/python3/dist-packages/cryptography/hazmat/backends/__init__.py", line 7, in <module>
[Fri Jul 05 12:39:18.752625 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] import pkg_resources
[Fri Jul 05 12:39:18.752834 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3019, in <module>
[Fri Jul 05 12:39:18.753009 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] #_call_aside
[Fri Jul 05 12:39:18.753215 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3003, in _call_aside
[Fri Jul 05 12:39:18.753405 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] f(*args, **kwargs)
[Fri Jul 05 12:39:18.753597 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3032, in _initialize_master_working_set
[Fri Jul 05 12:39:18.753806 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] working_set = WorkingSet._build_master()
[Fri Jul 05 12:39:18.754000 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 646, in _build_master
[Fri Jul 05 12:39:18.754175 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] ws = cls()
[Fri Jul 05 12:39:18.754390 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 639, in __init__
[Fri Jul 05 12:39:18.754590 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] self.add_entry(entry)
[Fri Jul 05 12:39:18.754782 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 695, in add_entry
[Fri Jul 05 12:39:18.754981 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] for dist in find_distributions(entry, True):
[Fri Jul 05 12:39:18.755178 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2012, in find_on_path
[Fri Jul 05 12:39:18.755382 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] if len(os.listdir(fullpath)) == 0:
[Fri Jul 05 12:39:18.755643 2019] [wsgi:error] [pid 74305] [remote 10.1.1.50:41450] PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.5/dist-packages/Werkzeug-0.15.4.dist-info'
I'm trying to deploy this application in a debian 9 server. I've tested it on my kali box and it worked fine just by installing flask and paramiko and configuring apache.
I've tried rinstalling some packages like paramiko, flask and Werkzeug but with no success.
I even created a new app with a simple hello world message. It works fine until i import paramiko and then i get the "permission denined" error.
My test app contains three files.
my_flask_app.py
from flask import Flask
import paramiko
app = Flask(__name__)
#app.route("/")
def hello():
return "Hello world!"
if __name__ == "__main__":
app.run()
my_flask_app.wsgi
import logging
import sys
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, '/var/www/html/ExampleFlask/ExampleFlask/')
from my_flask_app import app as application
application.secret_key = 'thisisasecretkey'
my_flask_app.conf
<VirtualHost *:80>
# Add machine's IP address (use ifconfig command)
ServerName 10.1.1.50
# Give an alias to to start your website url with
WSGIScriptAlias /testFlask /var/www/html/ExampleFlask/ExampleFlask/my_flask_app.wsgi
WSGIDaemonProcess my_flask_app user=www-data group=www-data threads=5
WSGIProcessGroup my_flask_app
#WSGIScriptAlias /testFlask /var/www/html/benchmarkerPHP/benchmarkerPHP.wsgi
#<Directory /var/www/html/benchmarkerPHP/>
<Directory /var/www/html/ExampleFlask/ExampleFlask/>
# set permissions as per apache2.conf file
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The apache user didn't have the needed permission to read from that directory. We only to add the read permission for the other group with the following command :
chmod o+r /usr/local/lib/python3.5/dist-packages/*

Problems Configuring mod_wsgi with Virtual Env

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.

Error 500 using apache 2.4: django ImportError: No module named 'myproject'

I am using Apache 2.4 with python 3.4 and corresponding version of mod_wsgi on a windows 2012 R2 server machine. All 64 bits. Right now after starting apache, I have this problem:
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator at admin#example.com to inform
them of the time this error occurred, and the actions you performed
just before this error.
More information about this error may be available in the server error
log.
So when going through the error log, I found those relevant lines (logging in debug mode):
The 'Apache2.4' service is restarting.
[Wed Oct 05 12:06:08.561983 2016] [mpm_winnt:notice] [pid 7756:tid 528] AH00424: Parent: Received restart signal -- Restarting the server.
[Wed Oct 05 12:06:08.561983 2016] [mpm_winnt:debug] [pid 10092:tid 456] child.c(1157): AH00357: Child: Exit event signaled. Child process is ending.
[Wed Oct 05 12:06:08.561983 2016] [mpm_winnt:debug] [pid 10092:tid 1000] child.c(735): AH00348: Child: Accept thread exiting.
[Wed Oct 05 12:06:08.561983 2016] [mpm_winnt:debug] [pid 10092:tid 996] child.c(735): AH00348: Child: Accept thread exiting.
[Wed Oct 05 12:06:08.577609 2016] [wsgi:warn] [pid 7756:tid 528] mod_wsgi: Compiled for Python/3.4.2.
[Wed Oct 05 12:06:08.577609 2016] [wsgi:warn] [pid 7756:tid 528] mod_wsgi: Runtime using Python/3.4.3.
[Wed Oct 05 12:06:08.577609 2016] [mpm_winnt:notice] [pid 7756:tid 528] AH00455: Apache/2.4.23 (Win64) mod_wsgi/4.4.12 Python/3.4.3 configured -- resuming normal operations
[Wed Oct 05 12:06:08.577609 2016] [mpm_winnt:notice] [pid 7756:tid 528] AH00456: Apache Lounge VC10 Server built: Jul 9 2016 11:59:00
[Wed Oct 05 12:06:08.577609 2016] [core:notice] [pid 7756:tid 528] AH00094: Command line: 'C:\\Apache24\\bin\\httpd.exe -d C:/Apache24'
[Wed Oct 05 12:06:08.577609 2016] [core:debug] [pid 7756:tid 528] log.c(1543): AH02639: Using SO_REUSEPORT: no (0)
[Wed Oct 05 12:06:08.577609 2016] [mpm_winnt:notice] [pid 7756:tid 528] AH00418: Parent: Created child process 10576
[Wed Oct 05 12:06:08.577609 2016] [mpm_winnt:debug] [pid 7756:tid 528] mpm_winnt.c(429): AH00402: Parent: Sent the scoreboard to the child
[Wed Oct 05 12:06:08.905752 2016] [wsgi:warn] [pid 10576:tid 456] mod_wsgi: Compiled for Python/3.4.2.
[Wed Oct 05 12:06:08.905752 2016] [wsgi:warn] [pid 10576:tid 456] mod_wsgi: Runtime using Python/3.4.3.
[Wed Oct 05 12:06:08.905752 2016] [mpm_winnt:debug] [pid 10576:tid 456] mpm_winnt.c(1718): AH00453: Child process is running
[Wed Oct 05 12:06:08.905752 2016] [wsgi:info] [pid 10576:tid 456] mod_wsgi (pid=10576): Initializing Python.
[Wed Oct 05 12:06:08.952607 2016] [wsgi:info] [pid 10576:tid 456] mod_wsgi (pid=10576): Attach interpreter ''.
[Wed Oct 05 12:06:08.952607 2016] [wsgi:info] [pid 10576:tid 456] mod_wsgi (pid=10576): Adding '\xe2\x80\x9cC:/Apache24/htdocs/EquipmentCalibration\xe2\x80\x9d' to path.
[Wed Oct 05 12:06:08.952607 2016] [mpm_winnt:debug] [pid 10576:tid 456] mpm_winnt.c(343): AH00391: Child: Retrieved our scoreboard from the parent.
[Wed Oct 05 12:06:08.952607 2016] [mpm_winnt:debug] [pid 10576:tid 456] mpm_winnt.c(465): AH00403: Child: Waiting for data for listening socket 0.0.0.0:8090
[Wed Oct 05 12:06:08.952607 2016] [mpm_winnt:debug] [pid 7756:tid 528] mpm_winnt.c(512): AH00408: Parent: Duplicating socket 500 (0.0.0.0:8090) and sending it to child process 10576
[Wed Oct 05 12:06:08.952607 2016] [mpm_winnt:debug] [pid 7756:tid 528] mpm_winnt.c(512): AH00408: Parent: Duplicating socket 540 ([::]:8090) and sending it to child process 10576
[Wed Oct 05 12:06:08.952607 2016] [mpm_winnt:debug] [pid 7756:tid 528] mpm_winnt.c(531): AH00411: Parent: Sent 2 listeners to child 10576
[Wed Oct 05 12:06:08.952607 2016] [mpm_winnt:debug] [pid 10576:tid 456] mpm_winnt.c(465): AH00403: Child: Waiting for data for listening socket [::]:8090
[Wed Oct 05 12:06:08.952607 2016] [mpm_winnt:debug] [pid 10576:tid 456] mpm_winnt.c(490): AH00407: Child: retrieved 2 listeners from parent
[Wed Oct 05 12:06:09.577635 2016] [mpm_winnt:debug] [pid 10092:tid 456] child.c(1214): AH00359: Child: Released the start mutex
[Wed Oct 05 12:06:09.577635 2016] [mpm_winnt:debug] [pid 10576:tid 456] child.c(1020): AH00352: Child: Acquired the start mutex.
[Wed Oct 05 12:06:09.577635 2016] [mpm_winnt:debug] [pid 10092:tid 456] child.c(1226): AH00361: Child: 64 threads blocked on the completion port
[Wed Oct 05 12:06:09.577635 2016] [mpm_winnt:notice] [pid 10576:tid 456] AH00354: Child: Starting 64 worker threads.
[Wed Oct 05 12:06:09.577635 2016] [mpm_winnt:debug] [pid 10576:tid 872] child.c(399): AH00334: Child: Accept thread listening on 0.0.0.0:8090 using AcceptFilter data
[Wed Oct 05 12:06:09.577635 2016] [mpm_winnt:debug] [pid 10576:tid 876] child.c(399): AH00334: Child: Accept thread listening on [::]:8090 using AcceptFilter data
[Wed Oct 05 12:06:10.581491 2016] [mpm_winnt:notice] [pid 10092:tid 456] AH00364: Child: All worker threads have exited.
[Wed Oct 05 12:06:10.581491 2016] [wsgi:info] [pid 10092:tid 456] mod_wsgi (pid=10092): Destroying interpreters.
[Wed Oct 05 12:06:10.581491 2016] [wsgi:info] [pid 10092:tid 456] mod_wsgi (pid=10092): Destroy interpreter 'PCTEST-IIS.pctestlab.com:8090|'.
[Wed Oct 05 12:06:10.581491 2016] [wsgi:info] [pid 10092:tid 456] mod_wsgi (pid=10092): End interpreter 'PCTEST-IIS.pctestlab.com:8090|'.
[Wed Oct 05 12:06:10.612772 2016] [wsgi:info] [pid 10092:tid 456] mod_wsgi (pid=10092): Cleanup interpreter ''.
[Wed Oct 05 12:06:10.644022 2016] [wsgi:info] [pid 10092:tid 456] mod_wsgi (pid=10092): Terminating Python.
[Wed Oct 05 12:06:10.659650 2016] [wsgi:info] [pid 10092:tid 456] mod_wsgi (pid=10092): Python has shutdown.
[Wed Oct 05 12:06:10.659650 2016] [mpm_winnt:debug] [pid 10092:tid 456] mpm_winnt.c(1723): AH00454: Child process is exiting
[Wed Oct 05 12:06:13.971571 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61169] AH01626: authorization result of Require all granted: granted
[Wed Oct 05 12:06:13.971571 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61169] AH01626: authorization result of <RequireAny>: granted
[Wed Oct 05 12:06:13.971571 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61169] AH01626: authorization result of Require all granted: granted
[Wed Oct 05 12:06:13.971571 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61169] AH01626: authorization result of <RequireAny>: granted
[Wed Oct 05 12:06:14.019608 2016] [wsgi:info] [pid 10576:tid 1116] mod_wsgi (pid=10576): Create interpreter 'PCTEST-IIS.pctestlab.com:8090|'.
[Wed Oct 05 12:06:14.050609 2016] [wsgi:info] [pid 10576:tid 1116] mod_wsgi (pid=10576): Adding '\xe2\x80\x9cC:/Apache24/htdocs/EquipmentCalibration\xe2\x80\x9d' to path.
[Wed Oct 05 12:06:14.053609 2016] [wsgi:info] [pid 10576:tid 1116] [client ::1:61169] mod_wsgi (pid=10576, process='', application='PCTEST-IIS.pctestlab.com:8090|'): Loading WSGI script 'C:/EquipmentCalibration/equipcal/wsgi.py'.
[Wed Oct 05 12:06:14.660623 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] mod_wsgi (pid=10576): Target WSGI script 'C:/EquipmentCalibration/equipcal/wsgi.py' cannot be loaded as Python module.
[Wed Oct 05 12:06:14.660623 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] mod_wsgi (pid=10576): Exception occurred processing WSGI script 'C:/EquipmentCalibration/equipcal/wsgi.py'.
[Wed Oct 05 12:06:14.660623 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] Traceback (most recent call last):\r
[Wed Oct 05 12:06:14.661628 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "C:/EquipmentCalibration/equipcal/wsgi.py", line 16, in <module>\r
[Wed Oct 05 12:06:14.661628 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] application = get_wsgi_application()\r
[Wed Oct 05 12:06:14.661628 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "C:\\Python34\\lib\\site-packages\\django\\core\\wsgi.py", line 13, in get_wsgi_application\r
[Wed Oct 05 12:06:14.661628 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] django.setup(set_prefix=False)\r
[Wed Oct 05 12:06:14.661628 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "C:\\Python34\\lib\\site-packages\\django\\__init__.py", line 22, in setup\r
[Wed Oct 05 12:06:14.661628 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\r
[Wed Oct 05 12:06:14.662625 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "C:\\Python34\\lib\\site-packages\\django\\conf\\__init__.py", line 53, in __getattr__\r
[Wed Oct 05 12:06:14.662625 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] self._setup(name)\r
[Wed Oct 05 12:06:14.662625 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "C:\\Python34\\lib\\site-packages\\django\\conf\\__init__.py", line 41, in _setup\r
[Wed Oct 05 12:06:14.662625 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] self._wrapped = Settings(settings_module)\r
[Wed Oct 05 12:06:14.662625 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "C:\\Python34\\lib\\site-packages\\django\\conf\\__init__.py", line 97, in __init__\r
[Wed Oct 05 12:06:14.662625 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] mod = importlib.import_module(self.SETTINGS_MODULE)\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "C:\\Python34\\Lib\\importlib\\__init__.py", line 109, in import_module\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] return _bootstrap._gcd_import(name[level:], package, level)\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "<frozen importlib._bootstrap>", line 2254, in _gcd_import\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "<frozen importlib._bootstrap>", line 2237, in _find_and_load\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "<frozen importlib._bootstrap>", line 2212, in _find_and_load_unlocked\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "<frozen importlib._bootstrap>", line 2254, in _gcd_import\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "<frozen importlib._bootstrap>", line 2237, in _find_and_load\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] ImportError: No module named 'equipcal'\r
[Wed Oct 05 12:06:14.678602 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61170] AH01626: authorization result of Require all granted: granted, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.678602 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61170] AH01626: authorization result of <RequireAny>: granted, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.679602 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61170] AH01626: authorization result of Require all granted: granted, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.679602 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61170] AH01626: authorization result of <RequireAny>: granted, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.679602 2016] [wsgi:info] [pid 10576:tid 1116] [client ::1:61170] mod_wsgi (pid=10576, process='', application='PCTEST-IIS.pctestlab.com:8090|'): Loading WSGI script 'C:/EquipmentCalibration/equipcal/wsgi.py'., referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.681602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] mod_wsgi (pid=10576): Target WSGI script 'C:/EquipmentCalibration/equipcal/wsgi.py' cannot be loaded as Python module., referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.681602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] mod_wsgi (pid=10576): Exception occurred processing WSGI script 'C:/EquipmentCalibration/equipcal/wsgi.py'., referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] Traceback (most recent call last):\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "C:/EquipmentCalibration/equipcal/wsgi.py", line 16, in <module>\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] application = get_wsgi_application()\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "C:\\Python34\\lib\\site-packages\\django\\core\\wsgi.py", line 13, in get_wsgi_application\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] django.setup(set_prefix=False)\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "C:\\Python34\\lib\\site-packages\\django\\__init__.py", line 22, in setup\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "C:\\Python34\\lib\\site-packages\\django\\conf\\__init__.py", line 53, in __getattr__\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] self._setup(name)\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "C:\\Python34\\lib\\site-packages\\django\\conf\\__init__.py", line 41, in _setup\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] self._wrapped = Settings(settings_module)\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "C:\\Python34\\lib\\site-packages\\django\\conf\\__init__.py", line 97, in __init__\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] mod = importlib.import_module(self.SETTINGS_MODULE)\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "C:\\Python34\\Lib\\importlib\\__init__.py", line 109, in import_module\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] return _bootstrap._gcd_import(name[level:], package, level)\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "<frozen importlib._bootstrap>", line 2254, in _gcd_import\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "<frozen importlib._bootstrap>", line 2237, in _find_and_load\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "<frozen importlib._bootstrap>", line 2212, in _find_and_load_unlocked\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "<frozen importlib._bootstrap>", line 2254, in _gcd_import\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "<frozen importlib._bootstrap>", line 2237, in _find_and_load\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] ImportError: No module named 'equipcal'\r, referer: http://localhost:8090/calbase/static
Apparently it looks like the problem is this:
Target WSGI script 'C:/EquipmentCalibration/equipcal/wsgi.py' cannot be loaded as Python module.
and:
ImportError: No module named 'equipcal'\r,
Where equipcal is my project name.
But this seems really weird, how could wsgi not loaded as python and my proejct not recognized? Especially I tried to add project directory into wsgi. My wsgi.py looks like this:
"""
WSGI config for equipcal 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/1.10/howto/deployment/wsgi/
"""
from django.core.wsgi import get_wsgi_application
import os, sys
sys.path.append('C:\Apache24\htdocs\EquipmentCalibration\equipcal')
sys.path.append('C:\Apache24\htdocs\EquipmentCalibration')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "equipcal.settings")
application = get_wsgi_application()
And in httpd.conf:
DocumentRoot "c:/Apache24/htdocs"
# Change Python path used by the server.
WSGIPythonPath “/EquipmentCalibration”
# Make calls to http://localhost/ refer to the Python/WSGI-script located at the specified location.
WSGIScriptAlias / /EquipmentCalibration/equipcal/wsgi.py
# Make calls to http://localhost/static refer to the specified folder.
Alias /static/ /EquipmentCalibration/static
Alias /media/ /EquipmentCalibration/media
<Directory /EquipmentCalibration/static>
Require all granted
</Directory>
<Directory /EquipmentCalibration/media>
Require all granted
</Directory>
<Directory /EquipmentCalibration/equipcal>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
my project is located as c:/Apache24/htdocs/EquipmentCalibration with project named equipcal.
With helps I figured out most other problem but got really stuck on this one. Could somebody please help me out?
Do I need something like a wsgi_handler.py?

How to set environ variables in local development with virtualenv

I am currently trying to publish via ZIP my django app to an AWS elasticbeanstalk.
As I have a local and online development enviroment I would like to make use of the environ variables, that are used anyways by AWS.
For my development environments I am already using virtualenv. Apache runs with wsgi enabled and is supposed to use such environments. Unfortunately, it does not know the environ that I have set in the bin/activate.
Django throws a 500 error, since it cannot connect to the database as it does not have access to the environ vars:
1:53.862779 2015] [wsgi:error] [pid 20639] [remote 127.0.0.1:51896] KeyError: 'RDS_DB_NAME'
If I activate my env and look into the env vars:
(myenv)[bs#debian-gohan:]/var/www/vhosts/mysite $ env | grep RDS
RDS_HOSTNAME=localhost
... and I get the others as well...
My Apache Vhost is:
<VirtualHost *:80>
WSGIDaemonProcess mysite python-path=/home/bs/envs/myenv/bin/python2.7:/home/bs/envs/myenv/lib/python2.7/site-packages
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/vhosts/main-page/mysite/wsgi.py
Does anyone have an idea why the environ vars are not seen by the apache ?
EDIT 1:
I have tried to use SetEnv in the Apache config, like this:
SetEnv RDS_HOSTNAME "localhost"
Unfortunately, this did not work. I then removed the ProcessGroup and only used a simple WSGIPythonPath. That did not work either.
The error in the apache log remains the same:
[Thu Mar 26 11:30:34.046807 2015] [wsgi:info] [pid 23012] [client 127.0.0.1:55231] mod_wsgi (pid=23012, process='', application='mysite.dbz.dev|'): Loading WSGI script '/var/www/vhosts/main-page/mysite/wsgi.py'.
[Thu Mar 26 11:30:34.178717 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] mod_wsgi (pid=23012): Target WSGI script '/var/www/vhosts/main-page/mysite/wsgi.py' cannot be loaded as Python module.
[Thu Mar 26 11:30:34.178812 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] mod_wsgi (pid=23012): Exception occurred processing WSGI script '/var/www/vhosts/main-page/mysite/wsgi.py'.
[Thu Mar 26 11:30:34.178924 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] Traceback (most recent call last):
[Thu Mar 26 11:30:34.178947 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/var/www/vhosts/main-page/mysite/wsgi.py", line 17, in <module>
[Thu Mar 26 11:30:34.179111 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] application = get_wsgi_application()
[Thu Mar 26 11:30:34.179157 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Thu Mar 26 11:30:34.179319 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] django.setup()
[Thu Mar 26 11:30:34.179363 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 20, in setup
[Thu Mar 26 11:30:34.179606 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Thu Mar 26 11:30:34.179651 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 46, in __getattr__
[Thu Mar 26 11:30:34.179774 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] self._setup(name)
[Thu Mar 26 11:30:34.179789 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup
[Thu Mar 26 11:30:34.179918 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] self._wrapped = Settings(settings_module)
[Thu Mar 26 11:30:34.179959 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 94, in __init__
[Thu Mar 26 11:30:34.180072 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] mod = importlib.import_module(self.SETTINGS_MODULE)
[Thu Mar 26 11:30:34.180112 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Thu Mar 26 11:30:34.180220 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] __import__(name)
[Thu Mar 26 11:30:34.180246 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/var/www/vhosts/main-page/mysite/../mysite/settings.py", line 94, in <module>
[Thu Mar 26 11:30:34.180400 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] 'NAME': os.environ['RDS_DB_NAME'],
[Thu Mar 26 11:30:34.180443 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
[Thu Mar 26 11:30:34.180613 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] raise KeyError(key)
[Thu Mar 26 11:30:34.180665 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] KeyError: 'RDS_DB_NAME'
Set like this
<VirtualHost hostname:80>
...
SetEnv VARIABLE_NAME variable_value
...
</VirtualHost>
In wsgi script.
os.environ.setdefault("variable", "value")
To override variable,
os.environ['var']="val"

Categories