> On 15 Sep 2020, at 10:17 pm, Daniel Gutiérrez <
dguti...@artaviaconsultoria.com> wrote:
>
>
> Hi, I want to host multiple Flask apps through Apache in the same Windows 10 server. I want each app to be running on different ports. I figured that each app must have its own Python configuration, otherwise Apache will only run one of the two web apps. I have seen that in Linux you are supposed to use WSGIDaemonProcess command in the VirtualHost file, but this does not work on Windows.
>
> I tried using
>
> import sys
> activate_this = 'C:/CRM4_Flask/venv/Scripts/activate_this.py'
> with open(activate_this) as file_:
> exec(file_.read(), dict(__file__=activate_this))
>
> #Expand Python classes path with your app’s path
> # The string inputted as the parameter corresponds to the web app's path in C
> sys.path.insert(0, "C:/CRM4_Flask")
>
> from run import app as application
>
> in my run.wsgi file for each app. However, I always get the following error:
>
> Fatal Python error: initfsencoding: unable to load the file system codec
> ModuleNotFoundError: No module named 'encodings'
This error has nothing to do with use of activate_this files and indicates that the Python libraries can't find your Python installation for some reason.
Still set WSGIPythonHome, but set it to where the main Python installation is located (not the virtual environment).
This should be the value of sys.prefix, or at least I hope so as I can't remember what Windows uses for the main Python installation.
> What alternative do I have instead of using WSGIDaemonProcess, given that it does not work on Windows? Im using Apache 2.4, Python 3.7.7, Windows 10 and mod_wsgi 4.7.1
>
> My VirtualHost configuration for one of the web apps I want to host is:
>
>
> <VirtualHost *:80>
>
> ServerName localhost:80
> ServerAlias localhost:80
> ServerAdmin
ad...@email.com
>
> DocumentRoot c:/CRM4_Flask
>
> <Directory c:/CRM4_Flask>
> Require all granted
> </Directory>
>
> WSGIScriptAlias / c:/CRM4_Flask/run.wsgi
> WSGIApplicationGroup %{GLOBAL}
Provided that both your WSGI applications only use third party modules that work fine in sub interpreters, all you need to do is NOT set WSGIApplicationGroup.
So long as you don't set it, each WSGI application will run in a separate Python sub interpreter of the same process and in the main shouldn't interfere with each other, or at least to the extent that sub interpreters separate things.
This is because sub interpreters are used by default, where the name of the sub interpreter is based on the name of the virtual host, the port, and the mount point of the WSGI application. So long as your two virtual hosts are on different ports (except for 80/443 which are still treated as one), they should be separate.
If you are using Python packages such as numpy then you will have a problem though. This is because numpy and thus a lot of the scientific packages for Python don't work in sub interpreters. Usually with those you would force the use of the main Python interpreter context. This is fine on Linux where have multiple apps which all need that to be done, as you can delegate each to separate daemon process groups. On Windows though you would be out of luck, as only one could be delegated to the main Python interpreter.
The directive which delegates the WGSI application to the main interpreter is:
WSGIApplicationGroup %{GLOBAL}
which is why I am asking you not to set it, cause right now you are telling both to run in the main interpreter, so they will conflict.
Graham