> On 11 Mar 2016, at 10:04 AM, Nana Okyere <[email protected]> wrote:
> 
> Graham,
> Great post. In my current set up, I have multiple flask python applications 
> hosted on multiple virtual hosts. 
> I have created only one virtual environment that all the applications use.
> 
> Outside of all the virtual hosts, I have:
> ##########################################
> WSGISocketPrefix /var/run/wsgi
> WSGIPythonHome /WebHA/catworld/featureanalytics-443S/webpython   #folder of 
> my virtualenv
> ########################################
> 
> Then in each virtual host, I have among others:
> #########################################
> DocumentRoot "/WebHA/catworld/featureanalytics-443S/workforce_tool/"
> ServerName wpat.cat.com
> ServerAlias wpat.cat.com
> 
> WSGIDaemonProcess wpat.cat.com user=http group=http processes=4 threads=4
> WSGIProcessGroup wpat.cat.com
> WSGIPassAuthorization On
> 
> WSGIScriptAlias / 
> /WebHA/catworld/featureanalytics-443S/workforce_tool/workforce_tool.wsgi
> Alias /static /WebHA/catworld/featureanalytics-443S/workforce_tool/app/static
> 
> <Directory /WebHA/catworld/featureanalytics-443S/workforce_tool/app/static/>
>     Order allow,deny
>     Allow from all
> </Directory>
> #######################################
> 
> 
> The corresponding wsgi file for the above virtual host is:
> ###############################################
> #workforce_tool.wsgi
> 
> #!/WebHA/catworld/featureanalytics-443S/webpython/bin/python
> 
> activate_this = 
> '/WebHA/catworld/featureanalytics-443S/webpython/bin/activate_this.py'
> exec(open(activate_this).read())
> 
> import sys
> import logging
> 
> logging.basicConfig(stream=sys.stderr)
> sys.path.insert(0,"/WebHA/catworld/featureanalytics-443S/workforce_tool/")
> 
> from app import theapp as application
> application.secret_key = 'mykey'
> #############################################
> 
> Python 3.4.3 
> mod_wsgi 4.4.22 
> Daemon mode
> 
> 
> I followed a tutorial online to set things up this way.
> For other reasons, I have to switch to use anaconda/conda distribution of 
> python. So I'll be creating conda environments for each app.

Before you can even do that, mod_wsgi would need to be uninstalled and 
recompiled from source code against the Anaconda Python distribution you want 
to use. I am not sure how well that will work as I have seen mixed reports 
about the Anaconda distribution and whether it will work. The issue I have 
heard of was with older versions, so later versions of Anaconda may work better.

> 1. How will the code in the wsgi file change especially about activating the 
> python environment? 

The activation of the Python virtual should be removed. You shouldn’t do it 
that way. Also don’t modify sys.path either.

> 2. How will my set up change to use a different conda environment for each 
> app/virtual host? I want to move away from using one environment for every 
> python app. 

You must have each application delegated to its own mod_wsgi daemon process.

Outside of all VirtualHost’s add:

    WSGIRestrictedEmbedded On

so you don’t accidentally run stuff in embedded mode.

You should then use options to WSGIDaemonProcess to specify the location of the 
virtual environment using the python-home option. Use python-path option to 
specify other directories to search.

    WSGIDaemonProcess wpat.cat.com user=http group=http processes=4 threads=4 
python-home=/WebHA/catworld/featureanalytics-443S/webpython 
python-path=/WebHA/catworld/featureanalytics-443S/workforce_tool

    WSGIProcessGroup wpat.cat.com <http://wpat.cat.com/>
    WSGIApplicationGroup %{GLOBAL}

    WSGIScriptAlias / 
/WebHA/catworld/featureanalytics-443S/workforce_tool/workforce_tool.wsgi

This config assumes one application per VirtualHost.

Note that have added WSGIApplicationGroup to force use of main Python 
interpreter context. This helps with some third party C extension modules for 
Python that will not work in sub interpreters. It is okay to override so long 
as only running one application per daemon process group.

For some reading see:

    
http://blog.dscpl.com.au/2014/09/using-python-virtual-environments-with.html 
<http://blog.dscpl.com.au/2014/09/using-python-virtual-environments-with.html>
    http://blog.dscpl.com.au/2014/09/python-module-search-path-and-modwsgi.html

Graham

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to