I am using a MS Windows 11 Machine running Python 3.11 with virtualenv
package installed.
I am using Apache24
httpd.exe
web server for my django
app production server.
My app is called mysite
and it is fully functional inside a virtual environment (called venv
) with the folowing packages (requirements.txt):
django
django-extensions
django-iprestrict
mod-wsgi
Pillow
pyOpenSSL
odfpy
werkzeug
whitenoise
pandas
plotly
matplotlib
I can fully run the server in DEBUG mode with the virtual environment activated:
(venv) python.exe manage.py runserver
And, on the other hand, I was able to make the Apache
web server to run a test website without problems.
The issue is when I edit httpd.conf
files to integrate with my django app thorugh mod_wsgi
:
# httpd.conf
(...)
LoadFile "C:/Users/myuser/AppData/Local/Programs/Python/Python311/python311.dll"
LoadModule "C:/Users/myuser/mysite/mysite_venv/venv/Lib/site-packages/mod_wsgi.cp311-win_amd64.pyd"
WSGIScriptAlias / C:Usersmyusermysitemysitewsgi.py
WSGIPythonHome C:Usersmyusermysitemysite_venvvenv
WSGIPythonPath C:Usersmyusermysite
<Directory />
<Files wsgi.py>
Require all granted
</Files>
</Directory>
# media files hosting
Alias /media "C:/Users/myuser/mysite/media/"
<Directory "C:/Users/myuser/mysite/media/">
Require all granted
</Directory>
(...)
My directory tree is:
.
├── mainapp
│ ├── admin.py
│ ├── apps.py
│ ├── forms.py
│ ├── __init__.py
│ ├── migrations
│ ├── models.py
│ ├── static
│ ├── templates
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── mainapp.sqlite3
├── manage.py
├── media
├── mysite
│ ├── asgi.py
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── mysite_venv
│ ├── requirements.txt
│ ├── venv
└── staticfiles
├── admin
├── css
├── django_extensions
├── font
├── icon
├── javascript
├── js
└── uploads
The issue is when I run httpd.exe
the web page loads forever because the server does not respond the client.
I have opened the error.txt
log file from Apache
to find out what is going on, but there was any error message about anything.
I took care about:
- setting
PYTHONPATH
environment variable to the DLLs as described here - natively compile and place the
mod_wsgi
.pyd
in the correct path.
Can someone help me what is going on? Thanks in advance!
2
Answers
There is some issue/conflict between modules
plotly
andmod_wsgi
that stucks the HTTP/S requests when Apache24 loads theplotly
module through WSGI.The same thing happens with
pandas
module, too.I could fix this problem by commenting all
views
andurls
that loads these modules.There is no problem about
virtualenv
having these modules installed, the issue is that they cannot be loaded bymod_wsgi
.The big question is that the development server works with them through
python manage.py runserver
, the issue is exactly when you put the server in production mode.I have a similar issue but using a Flask framework. I don’t think that it has anything to do with Django or Flask but it is an issue with Python and Apache 2.4 on Windows itself.
After installing the Apache2.4.57 on Windows it starts with the default webpage. No issue at all.
When I isntall the wsgi module to Python with pip install mod-wsgi everything works fine. The wsgi-mod is compiled and installed correctly.
When I modify the the httpd.conf file:
LoadFile "c:/python311/python311.dll"
LoadModule wsgi_module "c:/python311/lib/site-packages/mod_wsgi/server/mod_wsgi.cp311-win_amd64.pyd"
WSGIPythonHome "c:/python311/"
and start the httpd.exe again it fails with the following error:
httpd.exe: Syntax error on line 192 of C:/Apache24/conf/httpd.conf: Cannot load c:/python311/python311.dll into server: %1 is no Win32-application.
What does that mean? What do I need to configure additionally?