Closed PantaneiroCG closed 2 months ago
At a guess you should have:
WSGIPythonPath / "C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios"
You had it pointing at the wrong directory.
It should point to the parent directory of where your project is, not the project directory itself.
Graham, Thank you for your help and attention. I did as per your guidance, however, now it presents this error when starting Apache: AH00526: Syntax error on line 557 of C:/Apache24/conf/httpd.conf: WSGIPythonPath takes one argument, Python module search path.
New httpd.conf
Alias /robots.txt "C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios/static/robots.txt" Alias /favicon.ico "C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios/static/favicon.ico"
Alias /media/ "C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios/media/media" Alias /static/ "C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios/static"
<Directory "C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios/static"> Require all granted
<Directory "C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios/media/media"> Require all granted
LoadFile "C:/Python311/python311.dll" LoadModule wsgi_module "C:/Apache24/htdocs/Cadastro/env/Lib/site-packages/mod_wsgi-4.9.5.dev1-py3.11-win-amd64.egg/mod_wsgi/server/mod_wsgi.cp311-win_amd64.pyd" WSGIPythonHome "C:/Apache24/htdocs/Cadastro/env" WSGIScriptAlias / "C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios/projeto_cad_usuarios/wsgi.py" WSGIPythonPath / "C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios"
<Directory "C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios/projeto_cad_usuarios">
My mistake, I just copied what you had, which was in part wrong to start with ignoring the path issue.
Use:
WSGIPythonPath "C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios"
It should only be given one argument.
Okay, I commented out the line as below, then it returns to the previous error. Apache manages to start, but when trying to access the application through the browser, it presents the errors as in the log above and does not load the application.
I believe it's something I'm doing wrong in the httpd.conf configuration.
At the very start of the wsgi.py
file, before any imports, add:
import sys
print(sys.path)
What is the value for sys.path
that is printed out into the logs?
It was the first lines of the log and errors: [Mon Jul 03 20:17:05.036983 2023] [mpm_winnt:notice] [pid 11860:tid 512] AH00455: Apache/2.4.57 (Win64) mod_wsgi/4.9.5.dev1 Python/3.11 configured -- resuming normal operations [Mon Jul 03 20:17:05.036983 2023] [mpm_winnt:notice] [pid 11860:tid 512] AH00456: Apache Lounge VS17 Server built: May 31 2023 10:48:22 [Mon Jul 03 20:17:05.036983 2023] [core:notice] [pid 11860:tid 512] AH00094: Command line: 'httpd -d C:/Apache24' [Mon Jul 03 20:17:05.052589 2023] [mpm_winnt:notice] [pid 11860:tid 512] AH00418: Parent: Created child process 8440 [Mon Jul 03 20:17:05.413248 2023] [mpm_winnt:notice] [pid 8440:tid 512] AH00354: Child: Starting 64 worker threads.
You need to make a request to the WSGI application else you will not see the message as the wsgi.py
file will only be loaded when first request arrives. You may need to restart the Apache service as well if how things are setup means the wsgi.py
has been cached in memory.
With these httpd.conf settings, is this request not being made to the wsgi application? How to make this request correctly?
Using your web browser go to the same URL you have been using to try and access the application. The output of any print()
statements in the wsgi.py
should be displayed in the Apache error log if things are set correctly in the Apache config.
So did you try and access your web site or not?
Also ensure that LogLevel
is set to info
and not err
or warn
so can see when mod_wsgi loads the wsgi.py
. That will confirm you actually made a request and it was received properly.
Ahh yes, now I understand, I'm sorry that English is not my official language in my country. I'm going to configure Apache to show this message, I tried to access the application through the browser, but the messages that appeared in the log were those. Please, do not close this post, as I lost connection to the server I was accessing remotely and as soon as I resume I will continue my saga.. :-) And I will return with the result of the message as soon as possible.
Graham, thank you for your patience, I changed the apache configuration to info and new lines appeared in the log:
[Tue Jul 04 08:41:24.304642 2023] [wsgi:info] [pid 5348:tid 1248] [client 10.32.2.250:58795] mod_wsgi (pid=5348, process='', application='localhost:81|'): Loading Python script file 'C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios/projeto_cad_usuarios/wsgi.py'.
[Tue Jul 04 08:41:24.309629 2023] [wsgi:error] [pid 5348:tid 1248] [client 10.32.2.250:58795] mod_wsgi (pid=5348): Failed to exec Python script file 'C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios/projeto_cad_usuarios/wsgi.py'.
[Tue Jul 04 08:41:24.309629 2023] [wsgi:error] [pid 5348:tid 1248] [client 10.32.2.250:58795] mod_wsgi (pid=5348): Exception occurred processing WSGI script 'C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios/projeto_cad_usuarios/wsgi.py'.
[Tue Jul 04 08:41:24.310625 2023] [wsgi:error] [pid 5348:tid 1248] [client 10.32.2.250:58795] Traceback (most recent call last):\r
[Tue Jul 04 08:41:24.310625 2023] [wsgi:error] [pid 5348:tid 1248] [client 10.32.2.250:58795] File "C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios/projeto_cad_usuarios/wsgi.py", line 16, in
Graham, performing the tests I added the root folder in the line: "WSGIScriptAlias /projeto_cad_usuarios "C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios/projeto_cad_usuarios/wsgi.py" after the slash. As a result the lines below and in the browser only my project folders and files without rendering the application.
[Tue Jul 04 10:10:36.489918 2023] [mpm_winnt:notice] [pid 12816:tid 540] AH00455: Apache/2.4.57 (Win64) mod_wsgi/4.9.5.dev1 Python/3.11 configured -- resuming normal operations [Tue Jul 04 10:10:36.489918 2023] [mpm_winnt:notice] [pid 12816:tid 540] AH00456: Apache Lounge VS17 Server built: May 31 2023 10:48:22 [Tue Jul 04 10:10:36.489918 2023] [core:notice] [pid 12816:tid 540] AH00094: Command line: 'httpd -d C:/Apache24' [Tue Jul 04 10:10:36.489918 2023] [mpm_winnt:notice] [pid 12816:tid 540] AH00418: Parent: Created child process 5932 [Tue Jul 04 10:10:36.755479 2023] [wsgi:info] [pid 5932:tid 512] mod_wsgi (pid=5932): Initializing Python. [Tue Jul 04 10:10:36.771101 2023] [wsgi:info] [pid 5932:tid 512] mod_wsgi (pid=5932): Attach interpreter ''. [Tue Jul 04 10:10:36.771101 2023] [wsgi:info] [pid 5932:tid 512] mod_wsgi (pid=5932): Adding 'C:/Apache24/htdocs/Cadastro/env/Lib/site-packages' to path. [Tue Jul 04 10:10:36.786719 2023] [wsgi:info] [pid 5932:tid 512] mod_wsgi (pid=5932): Imported 'mod_wsgi'. [Tue Jul 04 10:10:36.802342 2023] [mpm_winnt:notice] [pid 5932:tid 512] AH00354: Child: Starting 64 worker threads.
When I stop apache:
[Tue Jul 04 10:21:36.901895 2023] [mpm_winnt:notice] [pid 12816:tid 540] AH00422: Parent: Received shutdown signal -- Shutting down the server. Apache server interrupted... Apache server interrupted... [Tue Jul 04 10:21:38.904605 2023] [mpm_winnt:notice] [pid 5932:tid 512] AH00364: Child: All worker threads have exited. [Tue Jul 04 10:21:38.904605 2023] [wsgi:info] [pid 5932:tid 512] mod_wsgi (pid=5932): Destroying interpreters. [Tue Jul 04 10:21:38.904605 2023] [wsgi:info] [pid 5932:tid 512] mod_wsgi (pid=5932): Cleanup interpreter ''. [Tue Jul 04 10:21:38.904605 2023] [wsgi:info] [pid 5932:tid 512] mod_wsgi (pid=5932): Terminating Python. [Tue Jul 04 10:21:38.919543 2023] [wsgi:info] [pid 5932:tid 512] mod_wsgi (pid=5932): Python has shutdown. [Tue Jul 04 10:21:38.944652 2023] [mpm_winnt:notice] [pid 12816:tid 540] AH00430: Parent: Child process 5932 exited successfully. [Tue Jul 04 10:21:38.945649 2023] [core:info] [pid 12816:tid 540] AH00096: removed PID file C:/Apache24/logs/httpd.pid (pid=12816)
Those last of logs with the exception traceback do not show any output that I can see corresponding to the lines:
import sys
print(sys.path)
which I told you to add. Were they added?
To make it more obvious, change it to:
import sys
print("PATH:", sys.path)
Ensure these two lines are the very first lines in the wsgi.py
file.
My file wsgi.py
import os import sys
print("PATH:", sys.path)
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'projeto_cad_usuarios.settings') application = get_wsgi_application()
I did before and now again. Below I am also sending new log:
access:
10.32.2.250 - - [06/Jul/2023:08:48:14 -0400] "GET /Cadastro/ HTTP/1.1" 200 322
error:
[Thu Jul 06 08:48:06.739594 2023] [mpm_winnt:notice] [pid 8536:tid 584] AH00455: Apache/2.4.57 (Win64) mod_wsgi/4.9.5.dev1 Python/3.11 configured -- resuming normal operations [Thu Jul 06 08:48:06.739594 2023] [mpm_winnt:notice] [pid 8536:tid 584] AH00456: Apache Lounge VS17 Server built: May 31 2023 10:48:22 [Thu Jul 06 08:48:06.739594 2023] [core:notice] [pid 8536:tid 584] AH00094: Command line: 'httpd -d C:/Apache24' [Thu Jul 06 08:48:06.739594 2023] [mpm_winnt:notice] [pid 8536:tid 584] AH00418: Parent: Created child process 10564 [Thu Jul 06 08:48:07.020787 2023] [wsgi:info] [pid 10564:tid 512] mod_wsgi (pid=10564): Initializing Python. [Thu Jul 06 08:48:07.036406 2023] [wsgi:info] [pid 10564:tid 512] mod_wsgi (pid=10564): Attach interpreter ''. [Thu Jul 06 08:48:07.052028 2023] [wsgi:info] [pid 10564:tid 512] mod_wsgi (pid=10564): Adding 'C:/Apache24/htdocs/Cadastro/env/Lib/site-packages' to path. [Thu Jul 06 08:48:07.067621 2023] [wsgi:info] [pid 10564:tid 512] mod_wsgi (pid=10564): Imported 'mod_wsgi'. [Thu Jul 06 08:48:07.067621 2023] [mpm_winnt:notice] [pid 10564:tid 512] AH00354: Child: Starting 64 worker threads.
There really wasn't anything corresponding to the ptint. I remember that when it was still giving an error, I did a test and a print appeared in the log, but with an error status:
**[Tue Jul 04 09:02:45.626529 2023] [wsgi:error] [pid 5348:tid 1248] teste***\r** [Tue Jul 04 09:02:45.629520 2023] [wsgi:error] [pid 5348:tid 1248] [client 10.32.2.250:58928] mod_wsgi (pid=5348): Failed to exec Python script file 'C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios/projeto_cad_usuarios/wsgi.py'. [Tue Jul 04 09:02:45.629520 2023] [wsgi:error] [pid 5348:tid 1248] [client 10.32.2.250:58928] mod_wsgi (pid=5348): Exception occurred processing WSGI script 'C:/Apache24/htdocs/Cadastro/projeto_cad_usuarios/projeto_cad_usuarios/wsgi.py'.
Hi Graham. I noticed that when I run the python development server, the result of the wsgi.py print command appears.
(env) C:\Apache24\htdocs\Cadastro\projeto_cad_usuarios>python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
July 06, 2023 - 15:00:44
Django version 2.1.15, using settings 'projeto_cad_usuarios.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
PATH: ['C:\\Apache24\\htdocs\\Cadastro\\projeto_cad_usuarios', 'C:\\Python311\\python311.zip', 'C:\\Python311\\DLLs', 'C:\\Python311\\Lib', 'C:\\Python311', 'C:\\Apache24\\htdocs\\Cadastro\\env', 'C:\\Apache24\\htdocs\\Cadastro\\env\\Lib\\site-packages', 'C:\\Apache24\\htdocs\\Cadastro\\env\\Lib\\site-packages\\mod_wsgi-4.9.5.dev1-py3.11-win-amd64.egg', 'C:\\Apache24\\htdocs\\Cadastro\\env\\Lib\\site-packages\\win32', 'C:\\Apache24\\htdocs\\Cadastro\\env\\Lib\\site-packages\\win32\\lib', 'C:\\Apache24\\htdocs\\Cadastro\\env\\Lib\\site-packages\\Pythonwin']
test.. test**********************
Did you ever sort this out? I have been travelling and so lots of stuff got neglected. Now only back and trying to catch up.
No solution for this problem so far.
I've been trying to put my django application in production for weeks and I got this situation:
mod_wsgi.py
httpd.conf
Show this message on the browser:
More information about this error may be available in the server error log.
I don't know where else to go, I'm using ApacheLounge after reading your recommendation in another post.