How to use Django with Apache? - django

Can someone help me and say whats wrong?
I need to use Django + Apache.
When I try to start Apache it shows me error: The requested operation has failed.
I tried to change Listen 80 to different values but it didnt help. Also this error appears after adding next settings to httpd.conf file (without these settings Apache start fine):
LoadModule wsgi_module modules/mod_wsgi.so
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
I use:
1) Apache 2.4 (x64)
2) Python 3.5.2 (x64)
3) Django 1.10.5
4) mod_wsgi‑4.5.15+ap24vc14‑cp35‑cp35m‑win_amd64.whl
5) Windows 8.1 (x64)
Maybe I use wrong mod_wsgi? I take mod_wsgi.cp35-win_amd64.pyd file from mod_wsgi‑4.5.15+ap24vc14‑cp35‑cp35m‑win_amd64.whl archive and rename that file to mod_wsgi.so. After that put that file to modules folder of Apache.
error.log file looks like this:
[Wed Jun 14 21:42:30.381146 2017] [mpm_winnt:notice] [pid 11892:tid 692] AH00455: Apache/2.4.2 (Win64) configured -- resuming normal operations
[Wed Jun 14 21:42:30.381146 2017] [mpm_winnt:notice] [pid 11892:tid 692] AH00456: Server built: May 11 2012 20:42:30
[Wed Jun 14 21:42:30.381146 2017] [core:notice] [pid 11892:tid 692] AH00094: Command line: 'C:\\Program Files\\Apache2.4\\bin\\httpd.exe -d C:/Program Files/Apache2.4 -f C:\\Program Files\\Apache2.4\\conf\\httpd.conf -d C:\\Program Files\\Apache2.4\\.'
[Wed Jun 14 21:42:30.381146 2017] [mpm_winnt:notice] [pid 11892:tid 692] AH00418: Parent: Created child process 13624
[Wed Jun 14 21:42:30.646739 2017] [mpm_winnt:notice] [pid 13624:tid 328] AH00354: Child: Starting 64 worker threads.
[Wed Jun 14 21:42:40.736467 2017] [mpm_winnt:notice] [pid 11892:tid 692] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Wed Jun 14 21:42:42.759516 2017] [mpm_winnt:notice] [pid 13624:tid 328] AH00364: Child: All worker threads have exited.
[Wed Jun 14 21:42:42.775140 2017] [mpm_winnt:notice] [pid 11892:tid 692] AH00430: Parent: Child process exited successfully.
[Wed Jun 14 21:42:51.755536 2017] [mpm_winnt:notice] [pid 7988:tid 696] AH00455: Apache/2.4.2 (Win64) configured -- resuming normal operations
[Wed Jun 14 21:42:51.756537 2017] [mpm_winnt:notice] [pid 7988:tid 696] AH00456: Server built: May 11 2012 20:42:30
[Wed Jun 14 21:42:51.756537 2017] [core:notice] [pid 7988:tid 696] AH00094: Command line: 'C:\\Program Files\\Apache2.4\\bin\\httpd.exe -d C:/Program Files/Apache2.4 -f C:\\Program Files\\Apache2.4\\conf\\httpd.conf -d C:\\Program Files\\Apache2.4\\.'
[Wed Jun 14 21:42:51.757538 2017] [mpm_winnt:notice] [pid 7988:tid 696] AH00418: Parent: Created child process 8692
[Wed Jun 14 21:42:51.973446 2017] [mpm_winnt:notice] [pid 8692:tid 636] AH00354: Child: Starting 64 worker threads.
[Wed Jun 14 21:59:11.710766 2017] [mpm_winnt:notice] [pid 7988:tid 696] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Wed Jun 14 21:59:13.712698 2017] [mpm_winnt:notice] [pid 8692:tid 636] AH00364: Child: All worker threads have exited.
[Wed Jun 14 21:59:13.731009 2017] [mpm_winnt:notice] [pid 7988:tid 696] AH00430: Parent: Child process exited successfully.
[Wed Jun 14 23:12:16.868389 2017] [mpm_winnt:notice] [pid 7988:tid 692] AH00455: Apache/2.4.2 (Win64) configured -- resuming normal operations
[Wed Jun 14 23:12:16.869389 2017] [mpm_winnt:notice] [pid 7988:tid 692] AH00456: Server built: May 11 2012 20:42:30
[Wed Jun 14 23:12:16.869389 2017] [core:notice] [pid 7988:tid 692] AH00094: Command line: 'C:\\Program Files\\Apache2.4\\bin\\httpd.exe -d C:/Program Files/Apache2.4 -f C:\\Program Files\\Apache2.4\\conf\\httpd.conf -d C:\\Program Files\\Apache2.4\\.'
[Wed Jun 14 23:12:16.870391 2017] [mpm_winnt:notice] [pid 7988:tid 692] AH00418: Parent: Created child process 7152
[Wed Jun 14 23:12:17.107601 2017] [mpm_winnt:notice] [pid 7152:tid 616] AH00354: Child: Starting 64 worker threads.
[Wed Jun 14 23:12:24.939591 2017] [mpm_winnt:notice] [pid 7988:tid 692] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Wed Jun 14 23:12:26.941397 2017] [mpm_winnt:notice] [pid 7152:tid 616] AH00364: Child: All worker threads have exited.
[Wed Jun 14 23:12:26.960081 2017] [mpm_winnt:notice] [pid 7988:tid 692] AH00430: Parent: Child process exited successfully.
wsgi.py:
import os, sys
sys.path.append('C:/Program Files/Apache2.4/htdocs/RMS/RMS')
sys.path.append('C:/Program Files/Apache2.4/htdocs/RMS')
os.environ.setdefault["DJANGO_SETTINGS_MODULE"] = "RMS.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandlers()
httpd-vhosts.conf:
<VirtualHost *:8080>
WSGIScriptAlias /rms 'C:/Program Files/Apache2.4/htdocs/RMS/RMS/wsgi.py'
Alias /media/ 'C:/Program Files/Apache2.4/htdocs/RMS/media'
Alias /media/ 'C:/Program Files/Apache2.4/htdocs/RMS/media'
<Directory "C:/Program Files/Apache2.4/htdocs/RMS/static">
<Files wsgi.py>
Order allow, deny
Allow from all
</Files>
</Directory>
<Directory "C:/Program Files/Apache2.4/htdocs/RMS/media">
Order allow, deny
Allow from all
</Directory>
</VirtualHost>
httpd.conf:
Listen 8080
LoadModule wsgi_module modules/mod_wsgi.so
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

The method Graham Dumpleton mentions is the way that worked for me, I was lucky enough to come across this item: modwgsi Google Group again by Graham.
Install mod_wsgi using pip (preferably into a virtualenv)
Run mod_wsgi-express module-config to get the settings to copy into your httpd.conf file, I chose to copy these above the LoadModules list.
Don't look to move and rename the .pyd file, leave it alone. To test, create a helloworld.wsgi with the following content:
def application(environ, start_response):
status = '200 OK'
output = b'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
In your VirtualHost, create a WSGIScriptAlias pointing to the wsgi file created, e.g. WSGIScriptAlias /test C:/wsgitest/helloworld.wsgi

Related

Django 4 with Apache 2.4 on Ubuntu 22.04 initially loading but then stops working until Apache restart

I deployed my Django 4 project with a SQLITE3 DB using python 3.10 on an Ubuntu 22.04 Server instance on a virtual machine on my Synology NAS. I am using the WSGI module, which is to my knowledge the only way to do this, right?
My Synology NAS has an Intel Celeron processes and 10GB RAM (2 cores and 6 GB are available to the virtual machine, I also tried first with 4 GB)
Now after I managed that my website can be called and is displayed I am facing the issue that I can call any page initially I want and it displays as expected BUT then the browser tab indicates by a moving circle that still something is loading and I cannot navigate to any other URL within my application. even the language is displayed correctly depending on the browser language.
It also happens that after I restarted apache the next page loaded. Doing this I was even able to login to the admin UI in 2 steps, so the database is obviously accessible.
Meanwhile increased the log level to trace1 of the Apache server and now can see that after 5 minutes the process gets killed and restarted for any reason but at least my environment variables are correctly loaded: This I can see by using print statements to show them in the logs. I also granted explicit complete rights für :www-data to my data base as it seems to me like the application or Apache has an issue with maybe writuing to the database.
Below you find extracts of the erorr log and Myebsite.log Yes, I called it like that :-)
So I hope somebody here has the right clue for me, to get this running.
Thank you in advance!
EXTRACT from MyWebsite.log
Between 20:43 and 20:48 nothing happens until the process stops.
[Thu Jan 26 20:43:24.001088 2023] [deflate:trace1] [pid 834] mod_deflate.c(734): [client 192.168.175.42:51447] token: 'gzip' - q: ''
[Thu Jan 26 20:43:24.158541 2023] [authz_core:debug] [pid 832] mod_authz_core.c(815): [client 192.168.175.42:51449] AH01626: authorization result of Require all granted: granted, referer: http://192.168.175.56/
[Thu Jan 26 20:43:24.158605 2023] [authz_core:debug] [pid 832] mod_authz_core.c(815): [client 192.168.175.42:51449] AH01626: authorization result of <RequireAny>: granted, referer: http://192.168.175.56/
[Thu Jan 26 20:43:24.158822 2023] [deflate:trace1] [pid 832] mod_deflate.c(734): [client 192.168.175.42:51449] token: 'gzip' - q: '', referer: http://192.168.175.56/
[Thu Jan 26 20:43:24.167348 2023] [deflate:debug] [pid 832] mod_deflate.c(869): [client 192.168.175.42:51449] AH01384: Zlib: Compressed 153402 to 22635 : URL /static/homepage/bootstrap.min.css, referer: http://192.168.175.56/
192.168.175.42 - - [26/Jan/2023:20:43:24 +0000] "GET /static/homepage/bootstrap.min.css HTTP/1.1" 200 22993 "http://192.168.175.56/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.61"
[Thu Jan 26 20:48:23.835110 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Daemon process deadlock timer expired, stopping process 'MyWebsite'.
[Thu Jan 26 20:48:23.835355 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Shutdown requested 'MyWebsite'.
[Thu Jan 26 20:48:24.023436 2023] [wsgi:error] [pid 834] (70007)The timeout specified has expired: [client 192.168.175.42:51447] mod_wsgi (pid=834): Failed to proxy response from daemon.
[Thu Jan 26 20:48:24.023582 2023] [deflate:debug] [pid 834] mod_deflate.c(869): [client 192.168.175.42:51447] AH01384: Zlib: Compressed 9409 to 3096 : URL /
192.168.175.42 - - [26/Jan/2023:20:43:13 +0000] "GET / HTTP/1.1" 200 3562 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.61"
[Thu Jan 26 20:48:24.087213 2023] [authz_core:debug] [pid 834] mod_authz_core.c(815): [client 192.168.175.42:51447] AH01626: authorization result of Require all granted: granted, referer: http://192.168.175.56/
[Thu Jan 26 20:48:24.087306 2023] [authz_core:debug] [pid 834] mod_authz_core.c(815): [client 192.168.175.42:51447] AH01626: authorization result of <RequireAny>: granted, referer: http://192.168.175.56/
192.168.175.42 - - [26/Jan/2023:20:48:24 +0000] "GET /static/homepage/minion_logo.png HTTP/1.1" 304 249 "http://192.168.175.56/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.61"
[Thu Jan 26 20:48:28.836028 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Aborting process 'MyWebsite'.
[Thu Jan 26 20:48:28.836241 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Exiting process 'MyWebsite'.
[Thu Jan 26 20:48:29.768996 2023] [wsgi:info] [pid 1239] mod_wsgi (pid=1239): Attach interpreter ''.
[Thu Jan 26 20:48:29.791601 2023] [wsgi:info] [pid 1239] mod_wsgi (pid=1239): Adding '/var/www/MyWebsite/MyWebsite' to path.
[Thu Jan 26 20:48:29.793603 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 0 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.794397 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 1 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.794441 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 4 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.794595 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 3 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.794677 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 2 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.794863 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 5 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.795137 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 6 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.795248 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 7 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.795994 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 14 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796116 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 13 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796215 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 12 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796293 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 9 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796373 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 11 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796496 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 10 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796591 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 8 in daemon process 'MyWebsite'.
EXTRACT error.log
[Thu Jan 26 20:42:52.685411 2023] [watchdog:debug] [pid 828] mod_watchdog.c(445): AH010033: Watchdog: Running with WatchdogInterval 1000ms
[Thu Jan 26 20:42:52.685641 2023] [watchdog:debug] [pid 828] mod_watchdog.c(454): AH02974: Watchdog: found parent providers.
[Thu Jan 26 20:42:52.685661 2023] [watchdog:debug] [pid 828] mod_watchdog.c(500): AH02977: Watchdog: found child providers.
[Thu Jan 26 20:42:52.685678 2023] [watchdog:debug] [pid 828] mod_watchdog.c(508): AH02978: Watchdog: Looking for child (_singleton_).
[Thu Jan 26 20:42:52.685694 2023] [watchdog:debug] [pid 828] mod_watchdog.c(508): AH02978: Watchdog: Looking for child (_default_).
[Thu Jan 26 20:42:52.686259 2023] [wsgi:debug] [pid 828] src/server/mod_wsgi.c(8512): mod_wsgi (pid=828): Socket for 'MyWebsite' is '/var/run/apache2/wsgi.828.0.1.sock'.
[Thu Jan 26 20:42:52.686405 2023] [wsgi:debug] [pid 828] src/server/mod_wsgi.c(8581): mod_wsgi (pid=828): Listen backlog for socket '/var/run/apache2/wsgi.828.0.1.sock' is '100'.
[Thu Jan 26 20:42:52.690541 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Starting process 'MyWebsite' with uid=33, gid=33 and threads=15.
[Thu Jan 26 20:42:52.705603 2023] [mpm_prefork:notice] [pid 828] AH00163: Apache/2.4.52 (Ubuntu) mod_wsgi/4.9.0 Python/3.10 configured -- resuming normal operations
[Thu Jan 26 20:42:52.705648 2023] [mpm_prefork:info] [pid 828] AH00164: Server built: 2022-09-30T04:09:50
[Thu Jan 26 20:42:52.705701 2023] [core:notice] [pid 828] AH00094: Command line: '/usr/sbin/apache2'
[Thu Jan 26 20:42:52.705719 2023] [core:debug] [pid 828] log.c(1570): AH02639: Using SO_REUSEPORT: yes (1)
[Thu Jan 26 20:42:52.705736 2023] [mpm_prefork:debug] [pid 828] prefork.c(953): AH00165: Accept mutex: none (default: pthread)
[Thu Jan 26 20:42:52.706664 2023] [watchdog:debug] [pid 831] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:42:52.707440 2023] [watchdog:debug] [pid 832] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:42:52.712781 2023] [watchdog:debug] [pid 834] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:42:52.713025 2023] [watchdog:debug] [pid 833] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:42:52.718786 2023] [wsgi:info] [pid 831] mod_wsgi (pid=831): Initializing Python.
[Thu Jan 26 20:42:52.719577 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Python home /var/www/MyWebsite/MyWebsite/venv.
[Thu Jan 26 20:42:52.719790 2023] [wsgi:info] [pid 832] mod_wsgi (pid=832): Initializing Python.
[Thu Jan 26 20:42:52.720365 2023] [wsgi:info] [pid 834] mod_wsgi (pid=834): Initializing Python.
[Thu Jan 26 20:42:52.720460 2023] [wsgi:info] [pid 833] mod_wsgi (pid=833): Initializing Python.
[Thu Jan 26 20:42:52.721846 2023] [watchdog:debug] [pid 830] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:42:52.722049 2023] [wsgi:info] [pid 830] mod_wsgi (pid=830): Initializing Python.
[Thu Jan 26 20:42:52.796422 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Initializing Python.
[Thu Jan 26 20:42:53.972677 2023] [wsgi:info] [pid 834] mod_wsgi (pid=834): Attach interpreter ''.
[Thu Jan 26 20:42:53.999176 2023] [wsgi:info] [pid 832] mod_wsgi (pid=832): Attach interpreter ''.
[Thu Jan 26 20:42:54.057680 2023] [wsgi:info] [pid 833] mod_wsgi (pid=833): Attach interpreter ''.
[Thu Jan 26 20:42:54.071090 2023] [wsgi:info] [pid 831] mod_wsgi (pid=831): Attach interpreter ''.
[Thu Jan 26 20:42:54.113752 2023] [wsgi:info] [pid 830] mod_wsgi (pid=830): Attach interpreter ''.
[Thu Jan 26 20:43:14.732936 2023] [watchdog:debug] [pid 1127] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:43:14.733171 2023] [wsgi:info] [pid 1127] mod_wsgi (pid=1127): Initializing Python.
[Thu Jan 26 20:43:14.792782 2023] [wsgi:info] [pid 1127] mod_wsgi (pid=1127): Attach interpreter ''.
[Thu Jan 26 20:43:24.421107 2023] [watchdog:debug] [pid 1128] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:43:24.421327 2023] [wsgi:info] [pid 1128] mod_wsgi (pid=1128): Initializing Python.
[Thu Jan 26 20:43:24.485083 2023] [wsgi:info] [pid 1128] mod_wsgi (pid=1128): Attach interpreter ''.
[Thu Jan 26 20:48:29.725192 2023] [wsgi:info] [pid 828] mod_wsgi (pid=829): Process 'MyWebsite' has died, deregister and restart it.
[Thu Jan 26 20:48:29.725334 2023] [wsgi:info] [pid 828] mod_wsgi (pid=829): Process 'MyWebsite' has been deregistered and will no longer be monitored.
[Thu Jan 26 20:48:29.726543 2023] [wsgi:info] [pid 1239] mod_wsgi (pid=1239): Starting process 'MyWebsite' with uid=33, gid=33 and threads=15.
[Thu Jan 26 20:48:29.730090 2023] [wsgi:info] [pid 1239] mod_wsgi (pid=1239): Python home /var/www/MyWebsite/MyWebsite/venv.
[Thu Jan 26 20:48:29.730296 2023] [wsgi:info] [pid 1239] mod_wsgi (pid=1239): Initializing Python.
Apache.conf seetings (i removed all commented lines)
DefaultRuntimeDir ${APACHE_RUN_DIR}
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 1
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel trace1
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
MyWebsite.conf
VirtualHost *:80>
ServerAdmin admin#MyWebsite.com
ServerName MyWebsite.com
ServerAlias www.MyWebsite.com
DocumentRoot /var/www/MyWebsite/MyWebsite/
ErrorLog ${APACHE_LOG_DIR}/MyWebsite.log
CustomLog ${APACHE_LOG_DIR}/MyWebsite.log combined
Alias /static /var/www/MyWebsite/MyWebsite/static
<Directory /var/www/MyWebsite/MyWebsite/static>
Require all granted
</Directory>
Alias /media /var/www/MyWebsite/MyWebsite/media
<Directory /var/www/MyWebsite/MyWebsite/media>
Require all granted
</Directory>
<Directory /var/www/MyWebsite/MyWebsite/MyWebsite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess MyWebsite python-path=/var/www/MyWebsite/MyWebsite python-home=/var/www/MyWebsite/MyWebsite/venv
WSGIProcessGroup MyWebsite
WSGIScriptAlias / /var/www/MyWebsite/MyWebsite/MyWebsite/wsgi.py
</VirtualHost>
WSGI.py
"""
WSGI config for MyWebsite 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/4.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'MyWebsite.settings')
application = get_wsgi_application()
from dotenv import load_dotenv
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
load_dotenv(dotenv_path)
List of Packages in VENV (python version: Python 3.10.6)
Package Version
----------------- -------
asgiref 3.6.0
autopep8 2.0.1
Django 4.1.4
django-countries 7.5
pip 22.0.2
pycodestyle 2.10.0
python-dotenv 0.21.0
setuptools 59.6.0
sqlparse 0.4.3
tomli 2.0.1
typing_extensions 4.4.0
tzdata 2022.7
its been a while but ... this is the steps I just took from a container based on Ubuntu Image:
> apt-get install apache2
> apt-get install apache2-dev
> ...env/bin/activate # activate virt env
> apt-get install mod_wsgi
> mod_wsgi-express module-config # run the command and copy 2 output lines (see below example) from terminal to apache config file (not inside vhost/host)
something like:
LoadModule wsgi_module "/var/www/project/env/lib/python3.10/site-packages/mod_wsgi/server/mod_wsgi-py310.cpython-310-x86_64-linux-gnu.so"
WSGIPythonHome "/var/www/project/env"
the rest seems ok in your vhost conf etc.

Django Apache - Virtualhost with HTTPS not starting

I just want to create a VirtualHost with Apache over https. I browsed half the internet but nothing could help me.
I'm using OpenSSL for the certificate and my OS is Windows.
Listen 443
<VirtualHost *:443>
ServerName www.foo.com
ServerAlias foo.com
SSLEngine On
SSLCertificateFile C:/Users/Myzel394/Documents/foo/certificate/aula_com.csr
SSLCertificateKeyFile C:/Users/Myzel394/Documents/foo/certificate/aula_com.key
DocumentRoot C:/Users/Myzel394/Documents/foo
WSGIScriptAlias / C:/Users/Myzel394/Documents/foo/foo/wsgi.py
<Directory C:/Users/Myzel394/Documents/foo/foo>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
My error message:
[Sun May 12 17:26:08.353667 2019] [ssl:warn] [pid 20204:tid 768] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:26:08.396654 2019] [ssl:warn] [pid 20204:tid 768] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:26:08.420646 2019] [mpm_winnt:notice] [pid 20204:tid 768] AH00455: Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.5 configured -- resuming normal operations
[Sun May 12 17:26:08.420646 2019] [mpm_winnt:notice] [pid 20204:tid 768] AH00456: Apache Lounge VC15 Server built: Mar 28 2018 12:12:41
[Sun May 12 17:26:08.420646 2019] [core:notice] [pid 20204:tid 768] AH00094: Command line: 'C:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Sun May 12 17:26:08.422646 2019] [mpm_winnt:notice] [pid 20204:tid 768] AH00418: Parent: Created child process 24792
[Sun May 12 17:26:08.943479 2019] [ssl:warn] [pid 24792:tid 732] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:26:08.977486 2019] [ssl:warn] [pid 24792:tid 732] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:26:09.003479 2019] [mpm_winnt:notice] [pid 24792:tid 732] AH00354: Child: Starting 150 worker threads.
[Sun May 12 17:28:47.449329 2019] [mpm_winnt:notice] [pid 20204:tid 768] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Sun May 12 17:28:49.450681 2019] [mpm_winnt:notice] [pid 24792:tid 732] AH00364: Child: All worker threads have exited.
[Sun May 12 17:28:49.470981 2019] [mpm_winnt:notice] [pid 20204:tid 768] AH00430: Parent: Child process 24792 exited successfully.
[Sun May 12 17:44:12.811155 2019] [ssl:warn] [pid 20096:tid 740] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:44:12.848141 2019] [ssl:warn] [pid 20096:tid 740] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:44:12.872133 2019] [mpm_winnt:notice] [pid 20096:tid 740] AH00455: Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.5 configured -- resuming normal operations
[Sun May 12 17:44:12.873133 2019] [mpm_winnt:notice] [pid 20096:tid 740] AH00456: Apache Lounge VC15 Server built: Mar 28 2018 12:12:41
[Sun May 12 17:44:12.873133 2019] [core:notice] [pid 20096:tid 740] AH00094: Command line: 'C:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Sun May 12 17:44:12.874133 2019] [mpm_winnt:notice] [pid 20096:tid 740] AH00418: Parent: Created child process 4512
[Sun May 12 17:44:13.311026 2019] [ssl:warn] [pid 4512:tid 664] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:44:13.344016 2019] [ssl:warn] [pid 4512:tid 664] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:44:13.370022 2019] [mpm_winnt:notice] [pid 4512:tid 664] AH00354: Child: Starting 150 worker threads.
[Sun May 12 17:44:14.456350 2019] [mpm_winnt:notice] [pid 20096:tid 740] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Sun May 12 17:44:16.457941 2019] [mpm_winnt:notice] [pid 4512:tid 664] AH00364: Child: All worker threads have exited.
[Sun May 12 17:44:16.475935 2019] [mpm_winnt:notice] [pid 20096:tid 740] AH00430: Parent: Child process 4512 exited successfully.
[Sun May 12 17:44:19.178024 2019] [ssl:warn] [pid 10936:tid 760] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:44:19.214875 2019] [ssl:warn] [pid 10936:tid 760] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:44:19.238868 2019] [mpm_winnt:notice] [pid 10936:tid 760] AH00455: Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.5 configured -- resuming normal operations
[Sun May 12 17:44:19.238868 2019] [mpm_winnt:notice] [pid 10936:tid 760] AH00456: Apache Lounge VC15 Server built: Mar 28 2018 12:12:41
[Sun May 12 17:44:19.238868 2019] [core:notice] [pid 10936:tid 760] AH00094: Command line: 'C:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Sun May 12 17:44:19.240867 2019] [mpm_winnt:notice] [pid 10936:tid 760] AH00418: Parent: Created child process 16324
[Sun May 12 17:44:19.779509 2019] [ssl:warn] [pid 16324:tid 660] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:44:19.815498 2019] [ssl:warn] [pid 16324:tid 660] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:44:19.840480 2019] [mpm_winnt:notice] [pid 16324:tid 660] AH00354: Child: Starting 150 worker threads.
[Sun May 12 17:44:20.718806 2019] [mpm_winnt:notice] [pid 10936:tid 760] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Sun May 12 17:44:22.719903 2019] [mpm_winnt:notice] [pid 16324:tid 660] AH00364: Child: All worker threads have exited.
[Sun May 12 17:44:22.738926 2019] [mpm_winnt:notice] [pid 10936:tid 760] AH00430: Parent: Child process 16324 exited successfully.
[Sun May 12 17:44:26.860235 2019] [ssl:warn] [pid 18248:tid 740] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:44:26.897262 2019] [ssl:warn] [pid 18248:tid 740] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:44:26.922251 2019] [mpm_winnt:notice] [pid 18248:tid 740] AH00455: Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.5 configured -- resuming normal operations
[Sun May 12 17:44:26.922251 2019] [mpm_winnt:notice] [pid 18248:tid 740] AH00456: Apache Lounge VC15 Server built: Mar 28 2018 12:12:41
[Sun May 12 17:44:26.922251 2019] [core:notice] [pid 18248:tid 740] AH00094: Command line: 'C:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Sun May 12 17:44:26.924250 2019] [mpm_winnt:notice] [pid 18248:tid 740] AH00418: Parent: Created child process 6996
[Sun May 12 17:44:27.370110 2019] [ssl:warn] [pid 6996:tid 716] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:44:27.403127 2019] [ssl:warn] [pid 6996:tid 716] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:44:27.430119 2019] [mpm_winnt:notice] [pid 6996:tid 716] AH00354: Child: Starting 150 worker threads.
[Sun May 12 17:44:29.776464 2019] [mpm_winnt:notice] [pid 18248:tid 740] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Sun May 12 17:44:31.777817 2019] [mpm_winnt:notice] [pid 6996:tid 716] AH00364: Child: All worker threads have exited.
[Sun May 12 17:44:31.796389 2019] [mpm_winnt:notice] [pid 18248:tid 740] AH00430: Parent: Child process 6996 exited successfully.
[Sun May 12 17:44:39.901770 2019] [ssl:warn] [pid 1032:tid 740] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:44:39.902765 2019] [ssl:emerg] [pid 1032:tid 740] AH02572: Failed to configure at least one certificate and key for www.www.foo.com:80
[Sun May 12 17:44:39.902765 2019] [ssl:emerg] [pid 1032:tid 740] SSL Library Error: error:0906D06C:PEM routines:PEM_read_bio:no start line (Expecting: DH PARAMETERS) -- Bad file contents or format - or even just a forgotten SSLCertificateKeyFile?
[Sun May 12 17:44:39.902765 2019] [ssl:emerg] [pid 1032:tid 740] SSL Library Error: error:0906D06C:PEM routines:PEM_read_bio:no start line (Expecting: EC PARAMETERS) -- Bad file contents or format - or even just a forgotten SSLCertificateKeyFile?
[Sun May 12 17:44:39.902765 2019] [ssl:emerg] [pid 1032:tid 740] SSL Library Error: error:140A80B1:SSL routines:SSL_CTX_check_private_key:no certificate assigned
[Sun May 12 17:44:39.902765 2019] [ssl:emerg] [pid 1032:tid 740] AH02312: Fatal error initialising mod_ssl, exiting.
AH00016: Configuration Failed
[Sun May 12 17:44:57.480579 2019] [ssl:warn] [pid 22708:tid 740] AH01909: www.example.com:50000:0 server certificate does NOT include an ID which matches the server name
[Sun May 12 17:44:57.481578 2019] [ssl:emerg] [pid 22708:tid 740] AH02562: Failed to configure certificate www.www.foo.com:443:0 (with chain), check C:/Users/Myzel394/Documents/foo/certificate/aula_com.csr
[Sun May 12 17:44:57.481578 2019] [ssl:emerg] [pid 22708:tid 740] SSL Library Error: error:0906D06C:PEM routines:PEM_read_bio:no start line (Expecting: TRUSTED CERTIFICATE) -- Bad file contents or format - or even just a forgotten SSLCertificateKeyFile?
[Sun May 12 17:44:57.481578 2019] [ssl:emerg] [pid 22708:tid 740] SSL Library Error: error:140DC009:SSL routines:use_certificate_chain_file:PEM lib
AH00016: Configuration Failed

how to solve mod_wsgi python conflict error

Hi all i am using Apache mod_wsgi to deploy a python application but i am getting internal server error as:
[Fri Nov 17 17:26:01.285539 2017] [mpm_event:notice] [pid 25751:tid 140495002072960] AH00491: caught SIGTERM, shutting down
[Fri Nov 17 17:26:02.395406 2017] [so:warn] [pid 26122:tid 140693819524992] AH01574: module wsgi_module is already loaded, skipping
[Fri Nov 17 17:26:02.396961 2017] [wsgi:warn] [pid 26123:tid 140693819524992] mod_wsgi: Compiled for Python/2.7.11.
[Fri Nov 17 17:26:02.396983 2017] [wsgi:warn] [pid 26123:tid 140693819524992] mod_wsgi: Runtime using Python/2.7.12.
[Fri Nov 17 17:26:02.397621 2017] [mpm_event:notice] [pid 26123:tid 140693819524992] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/2.7.12 configured -- resuming normal operations
[Fri Nov 17 17:26:02.397650 2017] [core:notice] [pid 26123:tid 140693819524992] AH00094: Command line: '/usr/sbin/apache2'
[Fri Nov 17 17:26:28.707573 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] mod_wsgi (pid=26126): Target WSGI script '/home/rajesh/mymapproxy/config.py' cannot be loaded as Python module.
[Fri Nov 17 17:26:28.707618 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] mod_wsgi (pid=26126): Exception occurred processing WSGI script '/home/rajesh/mymapproxy/config.py'.
[Fri Nov 17 17:26:28.707636 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] Traceback (most recent call last):
[Fri Nov 17 17:26:28.707655 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] File "/home/rajesh/mymapproxy/config.py", line 9, in
[Fri Nov 17 17:26:28.707703 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] from mapproxy.wsgiapp import make_wsgi_app
[Fri Nov 17 17:26:28.707747 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] ImportError: No module named mapproxy.wsgiapp
How can i fix this issue
Here is my apache configration: /etc/apche2/site-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ServerName localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIScriptAlias /mapproxy /home/rajesh/workspace/mymapproxy/config.py
WSGIApplicationGroup %{GLOBAL}
<Directory "/home/rajesh/workspace/mymapproxy/">
Order deny,allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
This is my /home/rajesh/workspace/mymapproxy/config.py
from mapproxy.wsgiapp import make_wsgi_app
application = make_wsgi_app(r'/etc/mapproxy.yaml')

Deploy Django on Apache 2.4

I have been trying to deploy my Django application on ubuntu 14.04 with the installed packages which are:
django 1.4.15
apache 2.4
python 2.7
mod_wsgi 3.4 (there is one compiled as mod_wsig.so-2.7 which is the one I use)
on my apache config I have this fields:
# Modules
LoadModule mpm_worker_module /usr/lib/apache2/modules/mod_mpm_worker.so
LoadModule mime_module /usr/lib/apache2/modules/mod_mime.so
LoadModule alias_module /usr/lib/apache2/modules/mod_alias.so
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so-2.7
LoadModule setenvif_module /usr/lib/apache2/modules/mod_setenvif.so
LoadModule authn_core_module /usr/lib/apache2/modules/mod_authn_core.so
LoadModule authz_core_module /usr/lib/apache2/modules/mod_authz_core.so
...
<Directory />
Options FollowSymLinks
AllowOverride None
AuthType none
Require all granted
</Directory>
...
# And finally the app config.
WSGIPythonHome /home/web/.virtualenvs/web
WSGIPythonPath /PATH/TO/MYSITE:/home/web/.virtualenvs/web/lib/python2.7/site-packages
WSGIScriptAlias / "/PATH/TO/wsgi.py"
Everything seems to be fine until I try to import one of the local modules in my system. By this I mean, the wsgi.py script runs no problem and then the django settings.py start running, in the settings I have this code:
from MYSITE.environments.prod_settings import *
environments is a module with it's own __init__.py file and all. but when it reaches that line it can't import.
The other part is that the site runs perfectly when I run ./manage.py runserver and the info in the sys.path is just the same!
I am just out of ideas on why apache wsgi will not let me import that python module.
Here is the latest logs:
[Fri Nov 28 18:07:06.222374 2014] [core:notice] [pid 3639:tid 140258688976768] AH00094: Command line: '/usr/sbin/apache2'
[Fri Nov 28 18:07:09.322057 2014] [:error] [pid 3642:tid 140258619721472] /home/web/.virtualenvs/web <--- printed the sys.prefix
[Fri Nov 28 18:07:09.673877 2014] [:error] [pid 3642:tid 140258619721472] 2014-11-28 18:07:09,670 (3642/MainThread) newrelic ERROR - Falling back to stderr logging as unable to create log file '/var/log/newrelic/newrelic-python-agent.log'.
[Fri Nov 28 18:07:09.673930 2014] [:error] [pid 3642:tid 140258619721472] Traceback (most recent call last):
[Fri Nov 28 18:07:09.673941 2014] [:error] [pid 3642:tid 140258619721472] File "/home/web/.virtualenvs/web/local/lib/python2.7/site-packages/newrelic-2.28.0.26/newrelic/common/log_file.py", line 79, in initialize_logging
[Fri Nov 28 18:07:09.673950 2014] [:error] [pid 3642:tid 140258619721472] _initialize_file_logging(log_file, log_level)
[Fri Nov 28 18:07:09.673959 2014] [:error] [pid 3642:tid 140258619721472] File "/home/web/.virtualenvs/web/local/lib/python2.7/site-packages/newrelic-2.28.0.26/newrelic/common/log_file.py", line 51, in _initialize_file_logging
[Fri Nov 28 18:07:09.673969 2014] [:error] [pid 3642:tid 140258619721472] handler = logging.FileHandler(log_file)
[Fri Nov 28 18:07:09.673977 2014] [:error] [pid 3642:tid 140258619721472] File "/usr/lib/python2.7/logging/__init__.py", line 903, in __init__
[Fri Nov 28 18:07:09.673985 2014] [:error] [pid 3642:tid 140258619721472] StreamHandler.__init__(self, self._open())
[Fri Nov 28 18:07:09.673993 2014] [:error] [pid 3642:tid 140258619721472] File "/usr/lib/python2.7/logging/__init__.py", line 928, in _open
[Fri Nov 28 18:07:09.674001 2014] [:error] [pid 3642:tid 140258619721472] stream = open(self.baseFilename, self.mode)
[Fri Nov 28 18:07:09.674009 2014] [:error] [pid 3642:tid 140258619721472] IOError: [Errno 13] Permission denied: '/var/log/newrelic/newrelic-python-agent.log'
[Fri Nov 28 18:07:09.985905 2014] [:error] [pid 3642:tid 140258619721472] No module named wizzytest2 <---- My module name
After the module error the logs errors are about problems with database connections in general. This happens because in the wizzytest2 module I have settings overrides so that is expected.
[Sat Nov 29 21:37:44.923879 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web' <-- python home
[Sat Nov 29 21:37:44.924177 2014] [:error] [pid 6097:tid 140297485195008] ['/home/web/.virtualenvs/web/lib/python2.7/site-packages',
[Sat Nov 29 21:37:44.924230 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/MYSITE/mysite',
[Sat Nov 29 21:37:44.924256 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/src/python-itunes',
[Sat Nov 29 21:37:44.924287 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/lib/python2.7',
[Sat Nov 29 21:37:44.924312 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/lib/python2.7/plat-x86_64-linux-gnu',
[Sat Nov 29 21:37:44.924342 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/lib/python2.7/lib-tk',
[Sat Nov 29 21:37:44.924366 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/lib/python2.7/lib-old',
[Sat Nov 29 21:37:44.924395 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/lib/python2.7/lib-dynload',
[Sat Nov 29 21:37:44.924419 2014] [:error] [pid 6097:tid 140297485195008] '/usr/lib/python2.7',
[Sat Nov 29 21:37:44.924449 2014] [:error] [pid 6097:tid 140297485195008] '/usr/lib/python2.7/plat-x86_64-linux-gnu',
[Sat Nov 29 21:37:44.924483 2014] [:error] [pid 6097:tid 140297485195008] '/usr/lib/python2.7/lib-tk',
[Sat Nov 29 21:37:44.924557 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/local/lib/python2.7/site-packages',
[Sat Nov 29 21:37:44.924583 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/local/lib/python2.7/site-packages/newrelic-2.28.0.26',
[Sat Nov 29 21:37:44.924615 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/lib/python2.7/site-packages',
[Sat Nov 29 21:37:44.924641 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/.virtualenvs/web/lib/python2.7/site-packages/newrelic-2.28.0.26',
[Sat Nov 29 21:37:44.924663 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/MYSITE',
[Sat Nov 29 21:37:44.924695 2014] [:error] [pid 6097:tid 140297485195008] '/home/web/MYSITE/mysite']
[Sat Nov 29 21:37:45.474168 2014] [:error] [pid 6097:tid 140297485195008] No module named wizzytest2
Just added the python path too so it's easier to debug. I also fixed the newrelic issue but that doesn't makes any difference on the settings file wizzytest2 been found or not.
Now with your logs I think the trouble is evident:
IOError: [Errno 13] Permission denied: '/var/log/newrelic/newrelic-python-agent.log/'
The user which launches your application doesn't have the right to write in '/var/log/newrelic/newrelic-python-agent.log'.
Maybe chmod -R +w '/var/log/newrelic/' can help you. But in fact, you should place the user which launch your app in an appropriate group which can write logs.
Note:
You should use uWSGI or Gunicorn for control you app and only use apache as frontend.
At the end this was an issue with permissions on the overriding settings file I wanted to import, at the end I just needed to do a chown web:web to the file and a chmod.

Django + Apache - wsgi trouble

I've been working with Django locally and now I'm trying to push some code to a production Apache environment on an Ubuntu server I have running (http://www.youtube.com/watch?v=hBMVVruB9Vs).
However, I just get a list of files in the directory and nothing else. First of all I ensured that Python was install by running the command Python at the terminal.
I've installed apaache and mod wsgi with the following commands:
sudo apt-get install apache2
sudo apt-get install libapache2-mod-wsgi
And I've tested to see that its enabled.
Here is my wsgi file firstweb.wsgi which is located in root:
import os
import sys
sys.path.append('/var/www/firstweb')
os.environ['DJANGO_SETTINGS_MODULE'] = 'firstweb.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Here is my firstweb.conf file:
<VirtualHost *:80>
WSGIScriptAlias / /firstweb.wsgi
Alias /static /var/www/firstweb/static
<Directory /var/www/firstweb/>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and my Django project is located in: /var/www/firstweb/
I honestly can't work out what is wrong here, within the video it is running fine! :(
Edit, here is error log:
[Sat Feb 16 16:19:31 2013] [notice] Apache/2.2.22 (Ubuntu) configured -- resuming normal operations
[Sat Feb 16 16:20:46 2013] [notice] caught SIGTERM, shutting down
[Sat Feb 16 16:20:47 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sat Feb 16 16:20:47 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sat Feb 16 16:20:47 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Sat Feb 16 16:37:05 2013] [notice] caught SIGTERM, shutting down
[Sat Feb 16 16:37:06 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sat Feb 16 16:37:06 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sat Feb 16 16:37:06 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Sat Feb 16 16:37:17 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:37:20 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:37:24 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:37:24 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:37:24 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:37:25 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:37:25 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:37:26 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:38:01 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:39:19 2013] [notice] caught SIGTERM, shutting down
[Sat Feb 16 16:39:20 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sat Feb 16 16:39:20 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sat Feb 16 16:39:20 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Sat Feb 16 16:39:24 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:39:42 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:48:00 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:48:02 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:49:51 2013] [notice] caught SIGTERM, shutting down
[Sat Feb 16 16:49:52 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sat Feb 16 16:49:52 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sat Feb 16 16:49:52 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Sat Feb 16 16:49:55 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:49:56 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:49:58 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:53:21 2013] [notice] caught SIGTERM, shutting down
[Sat Feb 16 16:53:22 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sat Feb 16 16:53:22 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sat Feb 16 16:53:22 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Sat Feb 16 16:55:34 2013] [notice] caught SIGTERM, shutting down
[Sat Feb 16 16:55:35 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sat Feb 16 16:55:35 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sat Feb 16 16:55:35 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Sat Feb 16 17:00:07 2013] [notice] caught SIGTERM, shutting down
[Sat Feb 16 17:00:08 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sat Feb 16 17:00:08 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sat Feb 16 17:00:08 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
Try configuring your virtualhost like so:
<Directory /var/www/firstweb/static>
Order allow,deny
Option Indexes
Allow from all
</Directory>
WSGIScriptAlias / /full-system-path-to/firstweb/wsgi.py
If that doesn't work - just make a change to the Directory tag and add static to the end like I have above - I think by not adding static, it's displaying the files in the directory
Configuring your virtualhost like:
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/production/myApp
<Directory />
Order Deny,Allow
Deny from all
Options None
AllowOverride None
</Directory>
<Directory /var/production/myApp>
Options None
AllowOverride None
Order allow,deny
allow from all
</Directory>
WSGIDaemonProcess mysite.com python-path=/var/production/myApp:/var/production/myApp/venv/lib/python2.7/site-packages
WSGIProcessGroup misite.com
WSGIScriptAlias / /var/production/myApp/myApp/wsgi.py
Alias /static /var/production/myApp/static
<Directory /var/production/myApp/static>
Options None
AllowOverride None
Order Allow,Deny
Allow from all
</Directory>
Replaces "/var/production/myApp" to your app path
If you need more help look at this tutorial
Question 1: Did you enable the wsgi mod?
sudo a2enmod mod-wsgi
Question 2: Where are your AddHandler statements?
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews ExecCGI
AddHandler cgi-script .cgi
AddHandler wsgi-script .wsgi
AllowOverride None
Order allow,deny
allow from all
</Directory>
I don't think apache knows how to associate .wsgi files to the wsgi application.