Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mod_wsgi with venv on windows, experiences on version 4.8.0 #663

Closed
tschuettenberg opened this issue Mar 18, 2021 · 1 comment
Closed

mod_wsgi with venv on windows, experiences on version 4.8.0 #663

tschuettenberg opened this issue Mar 18, 2021 · 1 comment

Comments

@tschuettenberg
Copy link

Dear Graham,
first of all thank you very much for your work. Your knowledgeable documentation and patient help on mod_wsgi are just great! Kudos!

I am an autodidact in these things but nevertheless currently preparing the installation of some (for me quite complex) applications (https://github.com/qwc-services/) in a virtual Python environment . Since the whole thing has to be done on Windows (without docker), I am of course also affected by the bug that prevents venv from working on Windows and even prevents the web server from starting (ModuleNotFoundError: No module named 'encodings'). So I dug into the issues (see e.g. #559 #535 #525 ) and seem to have gotten it working, so I'd like to share my experience.

My Setting:

  • OS Windows Server 2019 - 10.0.17763 (1809)
  • Apache 2.4.46 2021-02-18 (Build with Visual Studio® 2019 (VS16) x64) apachelounge
  • Python 3.7.0 64bit
  • pip 21.0.1
  • mod_wsgi 4.7.1 as well as 4.8.0

Sidenotes:

  1. the Python used here is from the OSGeo4W installer, as it is the basis of the essential module of my WebGIS, namely the QGIS server.
  2. This Python installation does NOT set any environment variables in the Windows system!

Insralling mod_wsgi 4.7.1 in venv:

D:\>python -m venv --system-site-packages D:\gdi\venvs\qwc

(qwc) D:\>python -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org mod_wsgi

(qwc) D:\>mod_wsgi-express module-config
LoadModule wsgi_module "D:/gdi/venvs/qwc/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "D:/gdi/venvs/qwc"

It is known that this configuration does not work, because LoadFile ...python37.dll is missing and WSGIPythonHome is not respected.
I found the solution to the first problem on the internet.
Because of the second one I tried infinite combinations of entries in httpd.conf and environment variables and finally found that setting WSGIPythonHome "D:/gdi/qgisServer/apps/Python37" allows the Apache to start again and the Hello World wsgi script works!

The corresponding log with LogLevel info and WSGIVerboseDebugging On looks like this:

Starting the 'Apache 2.4 geoapp' service
The 'Apache 2.4 geoapp' service is running.
 [pid 10092:tid 728] AH01887: Init: Initializing (virtual) servers for SSL
[Thu Mar 18 14:32:24.787981 2021] [ssl:info] [pid 10092:tid 728] AH01876: mod_ssl/2.4.46 compiled against Server: Apache/2.4.46, Library: OpenSSL/1.1.1j
[Thu Mar 18 14:32:24.866111 2021] [socache_shmcb:info] [pid 10092:tid 728] AH00830: Shared memory socache initialised
[Thu Mar 18 14:32:24.866111 2021] [ssl:info] [pid 10092:tid 728] AH01887: Init: Initializing (virtual) servers for SSL
[Thu Mar 18 14:32:24.866111 2021] [ssl:info] [pid 10092:tid 728] AH01876: mod_ssl/2.4.46 compiled against Server: Apache/2.4.46, Library: OpenSSL/1.1.1j
[Thu Mar 18 14:32:24.866111 2021] [mpm_winnt:notice] [pid 10092:tid 728] AH00455: Apache/2.4.46 (Win64) OpenSSL/1.1.1j mod_fcgid/2.3.10-dev mod_wsgi/4.7.1 Python/3.7 configured -- resuming normal operations
[Thu Mar 18 14:32:24.866111 2021] [mpm_winnt:notice] [pid 10092:tid 728] AH00456: Apache Lounge VS16 Server built: Feb 17 2021 13:11:14
[Thu Mar 18 14:32:24.866111 2021] [core:notice] [pid 10092:tid 728] AH00094: Command line: 'D:\\gdi\\Apache24\\bin\\httpd.exe -d D:/gdi/Apache24 -f D:\\gdi\\configurations\\httpd.conf -f d:/gdi/configurations/httpd.conf'
[Thu Mar 18 14:32:24.881738 2021] [mpm_winnt:notice] [pid 10092:tid 728] AH00418: Parent: Created child process 1584
[Thu Mar 18 14:32:25.428615 2021] [ssl:info] [pid 1584:tid 632] AH01887: Init: Initializing (virtual) servers for SSL
[Thu Mar 18 14:32:25.444234 2021] [ssl:info] [pid 1584:tid 632] AH01876: mod_ssl/2.4.46 compiled against Server: Apache/2.4.46, Library: OpenSSL/1.1.1j
[Thu Mar 18 14:32:25.522356 2021] [socache_shmcb:info] [pid 1584:tid 632] AH00830: Shared memory socache initialised
[Thu Mar 18 14:32:25.522356 2021] [ssl:info] [pid 1584:tid 632] AH01887: Init: Initializing (virtual) servers for SSL
[Thu Mar 18 14:32:25.522356 2021] [ssl:info] [pid 1584:tid 632] AH01876: mod_ssl/2.4.46 compiled against Server: Apache/2.4.46, Library: OpenSSL/1.1.1j
[Thu Mar 18 14:32:25.522356 2021] [wsgi:info] [pid 1584:tid 632] mod_wsgi (pid=1584): Python home D:/gdi/qgisServer/apps/Python37.
[Thu Mar 18 14:32:25.522356 2021] [wsgi:info] [pid 1584:tid 632] mod_wsgi (pid=1584): Initializing Python.
[Thu Mar 18 14:32:25.553638 2021] [wsgi:info] [pid 1584:tid 632] mod_wsgi (pid=1584): Attach interpreter ''.
[Thu Mar 18 14:32:25.553638 2021] [mpm_winnt:notice] [pid 1584:tid 632] AH00354: Child: Starting 64 worker threads.
[Thu Mar 18 14:32:30.543459 2021] [wsgi:info] [pid 1584:tid 1324] mod_wsgi (pid=1584): Create interpreter 'webgis.minden.de|/myapp'.

same with mod_wsgi 4.8.0
As often advised I then tried the whole thing again with mod_wsgi 4.8.0 (e.g. #559 (comment)):

D:\>python -m venv --system-site-packages D:\gdi\venvs\test1
 
(test1) D:\>python -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org --upgrade pip
 
(test1) D:\>python -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org --no-cache-dir -U "D:\zeug\GrahamDumpleton\mod_wsgi-develop.zip" 
Processing d:\zeug\grahamdumpleton\mod_wsgi-develop.zip
Using legacy 'setup.py install' for mod-wsgi, since package 'wheel' is not installed.
Installing collected packages: mod-wsgi
    Running setup.py install for mod-wsgi ... /    WARNING: Subprocess output does not appear to be encoded as cp1252
    WARNING: Subprocess output does not appear to be encoded as cp1252
done
Successfully installed mod-wsgi-4.8.0
 
(test1) D:\>mod_wsgi-express module-config
LoadFile "D:/gdi/qgisServer/apps/Python37/python37.dll"
LoadModule wsgi_module "D:/gdi/venvs/test1/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "D:/gdi/venvs/test1"

The output of module-configis only a valid configuration for me, IF I also add the environment variable PYTHONHOME with D:\gdi\qgisServer\apps\Python37to the windows system.

In the resulting log you may find some little differences:

Starting the 'Apache 2.4 geoapp' service
The 'Apache 2.4 geoapp' service is running.
 [pid 3004:tid 692] AH01887: Init: Initializing (virtual) servers for SSL
[Thu Mar 18 14:17:12.514903 2021] [ssl:info] [pid 3004:tid 692] AH01876: mod_ssl/2.4.46 compiled against Server: Apache/2.4.46, Library: OpenSSL/1.1.1j
[Thu Mar 18 14:17:12.608652 2021] [socache_shmcb:info] [pid 3004:tid 692] AH00830: Shared memory socache initialised
[Thu Mar 18 14:17:12.608652 2021] [ssl:info] [pid 3004:tid 692] AH01887: Init: Initializing (virtual) servers for SSL
[Thu Mar 18 14:17:12.608652 2021] [ssl:info] [pid 3004:tid 692] AH01876: mod_ssl/2.4.46 compiled against Server: Apache/2.4.46, Library: OpenSSL/1.1.1j
[Thu Mar 18 14:17:12.608652 2021] [mpm_winnt:notice] [pid 3004:tid 692] AH00455: Apache/2.4.46 (Win64) OpenSSL/1.1.1j mod_fcgid/2.3.10-dev mod_wsgi/4.8.0 Python/3.7 configured -- resuming normal operations
[Thu Mar 18 14:17:12.608652 2021] [mpm_winnt:notice] [pid 3004:tid 692] AH00456: Apache Lounge VS16 Server built: Feb 17 2021 13:11:14
[Thu Mar 18 14:17:12.608652 2021] [core:notice] [pid 3004:tid 692] AH00094: Command line: 'D:\\gdi\\Apache24\\bin\\httpd.exe -d D:/gdi/Apache24 -f D:\\gdi\\configurations\\httpd.conf -f d:/gdi/configurations/httpd.conf'
[Thu Mar 18 14:17:12.608652 2021] [mpm_winnt:notice] [pid 3004:tid 692] AH00418: Parent: Created child process 352
[Thu Mar 18 14:17:13.202489 2021] [ssl:info] [pid 352:tid 656] AH01887: Init: Initializing (virtual) servers for SSL
[Thu Mar 18 14:17:13.202489 2021] [ssl:info] [pid 352:tid 656] AH01876: mod_ssl/2.4.46 compiled against Server: Apache/2.4.46, Library: OpenSSL/1.1.1j
[Thu Mar 18 14:17:13.311794 2021] [socache_shmcb:info] [pid 352:tid 656] AH00830: Shared memory socache initialised
[Thu Mar 18 14:17:13.311794 2021] [ssl:info] [pid 352:tid 656] AH01887: Init: Initializing (virtual) servers for SSL
[Thu Mar 18 14:17:13.311794 2021] [ssl:info] [pid 352:tid 656] AH01876: mod_ssl/2.4.46 compiled against Server: Apache/2.4.46, Library: OpenSSL/1.1.1j
[Thu Mar 18 14:17:13.311794 2021] [wsgi:info] [pid 352:tid 656] mod_wsgi (pid=352): Initializing Python.
[Thu Mar 18 14:17:13.343065 2021] [wsgi:info] [pid 352:tid 656] mod_wsgi (pid=352): Attach interpreter ''.
[Thu Mar 18 14:17:13.358671 2021] [wsgi:info] [pid 352:tid 656] mod_wsgi (pid=352): Adding 'D:/gdi/venvs/test1/Lib/site-packages' to path.
[Thu Mar 18 14:17:13.374298 2021] [wsgi:info] [pid 352:tid 656] mod_wsgi (pid=352): Imported 'mod_wsgi'.
[Thu Mar 18 14:17:13.374298 2021] [mpm_winnt:notice] [pid 352:tid 656] AH00354: Child: Starting 64 worker threads.
[Thu Mar 18 14:17:15.244188 2021] [wsgi:info] [pid 352:tid 1328] mod_wsgi (pid=352): Create interpreter 'webgis.minden.de|/myapp'.
[Thu Mar 18 14:17:15.259821 2021] [wsgi:info] [pid 352:tid 1328] mod_wsgi (pid=352): Adding 'D:/gdi/venvs/test1/Lib/site-packages' to path.

Whether there is a relevant difference between these two setups (for my intended productive environment) is unfortunately beyond my understanding. For instance

  • WSGIPythonHome "D:/gdi/venvs/test1" points to pyvenv.cfg, which says home = D:\gdi\qgisServer\apps\Python37 - So, what's the real difference?
  • Should I (already) use 4.8.0? When will it be released?
  • I was also surprised that LoadFile is not set to the dll in the venv, which - by the way - also works for me.

Since the whole thing is a bit of a pain on Windows, I'm curious if it will end up working with the QWC services as well.... ;-)
Any further advice apprechiated, thanks again!
Cheers,
Thomas

@GrahamDumpleton
Copy link
Owner

Closing issue is information only and no issue to address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants