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.
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/dieweltdahinter_project/env/lib/python3.10/site-packages/mod_wsgi/server/mod_wsgi-py310.cpython-310-x86_64-linux-gnu.so"
WSGIPythonHome "/var/www/dieweltdahinter_project/env"
the rest seems ok in your vhost conf etc.