Comments inline.

> On 14 Jun 2018, at 8:52 am, Rajeev Jain <jainr...@gmail.com> wrote:
> 
> So you know for future. In a multi part email chain it can be difficult to go 
> back and extract what configuration may have been used that you might be 
> referring to. So when you ask questions you should always repeat what is 
> occurring in your case. It is even better not to reply on a previous email 
> chain and the history of the previous issue, which may not be the same, can 
> just confuse things. So I am just going to ask for the configuration again.
> 
> Understood. No problem. 
> 
> Where is the Flask package installed?
> 
> On my Ubuntu 16.04 system, anaconda python and all python modules are 
> installed in my home directory. There is no virtual environment. When I 
> log-in the PATH environment variable is set so any invocation of python uses 
> the desired python distribution. All my python code is able to find all other 
> installed modules. There is history and legacy here. 
> 
> My immediate objective is to have the Apache server boot and use the python 
> distribution in my home directory for all Flask/WSGI related processing.
> 
> 
> From the command line, if you run the 'python' you want to use, what do you 
> get when from the interpreter you do:
> 
>     import flask
>     print(flask.__file__)
> 
> /home/rajeev/anaconda3/lib/python3.6/site-packages/flask/__init__.py
>  
> 
> Also what do you get for:
> 
>     import sys
>     print(sys.prefix)
> 
> /home/rajeev/anaconda3
> 
> 
>  
> The prior configuration example in the email chain was not setting up the 
> Python virtual environment correctly so can't be used as a guide.
> 
> I need to see what is in the wsgi.load file if still using system package for 
> mod_wsgi.
> 
> /etc/apache2/mods-enabled$ cat wsgi.load 
> LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

It is probably better to have run:

    mod_wsgi-express module-config

That should give you a LoadModule line for loading the mod_wsgi.so file from 
the place it is installed, as well as a LoadFile which loads the correct Python 
shared library for Anaconda, so the system Python library isn't picked up by 
mistake. Add the output of that into wsgi.load in place of what you have.

> 
> notes:
> 1) was able to successfully pip install mod_wsgi
> pip install mod_wsgi
> Requirement already satisfied: mod_wsgi in 
> ./anaconda3/lib/python3.6/site-packages (4.6.4)
> 
> 2) updated softlink to use new object
> /usr/lib/apache2/modules$ ll mod_wsg*
> -rwxr-xr-x 1 root root 974744 Jun 13 14:45 
> mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so*
> lrwxrwxrwx 1 root root     45 Jun 13 14:47 mod_wsgi.so -> 
> mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so*
> 
> -rw-r--r-- 1 root root 207952 Jan 25  2016 mod_wsgi.so-3.5
> 
> 3) server log shows the new mod_wsgi is being loaded.
> 
> tail -l /var/log/apache2/error.log
> [Wed Jun 13 15:08:13.942743 2018] [mpm_prefork:notice] [pid 23851] AH00169: 
> caught SIGTERM, shutting down
> [Wed Jun 13 15:12:14.024133 2018] [ssl:warn] [pid 24110] AH01909: 
> 198.105.244.228:443:0 server certificate does NOT include an ID which matches 
> the server name
> [Wed Jun 13 15:12:14.114890 2018] [ssl:warn] [pid 24111] AH01909: 
> 198.105.244.228:443:0 server certificate does NOT include an ID which matches 
> the server name
> [Wed Jun 13 15:12:14.121149 2018] [mpm_prefork:notice] [pid 24111] AH00163: 
> Apache/2.4.18 (Ubuntu) OpenSSL/1.0.2g mod_wsgi/4.6.4 Python/3.6 configured -- 
> resuming normal operations
> [Wed Jun 13 15:12:14.121185 2018] [core:notice] [pid 24111] AH00094: Command 
> line: '/usr/sbin/apache2'
>  
> 
> I then need to see what you may have set WSGIPythonHome, WSGIPythonPath, and 
> general configuration for mod_wsgi in the VirtualHost, including 
> WSGIDaemonProcess. Basically, include all what you are using in your 
> response. I really need to see what you are using, and not what someone else 
> used, even if you think it is the same.
> 
> 
> /etc/apache2/mods-enabled$ cat wsgi.conf 
> <IfModule mod_wsgi.c>
> 
>     WSGIPythonHome /home/rajeev/anaconda3
>     WSGIPythonPath /home/rajeev/anaconda3/lib/python3.6/site-packages
> 
> </IfModule>

Instead of WSGIPythonHome and WSGIPythonPath here, have:

    WSGIRestrictEmbedded On

That will turn off embedded mode and if configuration is wrong and application 
is not delegated to daemon mode processes correctly, you will get a 500 error 
to tell you you have an issue.

>  /etc/apache2/sites-available$ cat FlaskApp.conf 
> <VirtualHost *:83>
>     ServerName flaskapp.com <http://flaskapp.com/>
> 
>     WSGIDaemonProcess flaskapp.com <http://flaskapp.com/> 
> python-path=/home/rajeev/anaconda3

This is not correct. Use:

    WSGIDaemonProcess flaskapp.com python-home=/home/rajeev/anaconda3

>     WSGIProcessGroup %{GLOBAL}

The problem with the daemon process configuration wasn't noticeable because you 
are using the wrong value for WSGIProcessGroup. You were telling it to use 
embedded mode instead.

> 
>     WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi

I would suggest removing the WSGIProcessGroup above and change this to:

    WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi 
process-group=flaskapp.com <http://flaskapp.com/> application-group=%{GLOBAL}

This is ensuring daemon process group is used, and also the main interpreter 
context.

>     <Directory /var/www/FlaskApp/FlaskApp/>

This path is incorrect. Should be:

    <Directory /var/www/FlaskApp>

Better still use:

    <Directory /var/www/FlaskApp>
    <Files flaskapp.wsgi>
    Require all granted
   </Files>
    </Directory>

since you have your project source code under the same directory. 

That you don't get forbidden at the moment suggests for some reason the overall 
Apache configuration has been weakened in some way such that anything on the 
whole file system can be served up if mapped, which isn't really a good idea.

>         Require all granted
>     </Directory>
> </VirtualHost>
> 
> Also show anything you have added in the WSGI script file to try and activate 
> a virtual environment, or changes you are making to sys.path.
> 
> /var/www/FlaskApp$ cat flaskapp.wsgi 
> #!/home/rajeev/anaconda3/bin/python
> import sys
> import logging
> logging.basicConfig(stream=sys.stderr)
> sys.path.insert(0,"/var/www/FlaskApp/")
> 
> from FlaskApp import app as application
> application.secret_key = 'Add your secret key'
> 
> Testing:
> curl -sH 'Host: flaskapp.com <http://flaskapp.com/>' localhost:83|grep title
> <title>500 Internal Server Error</title>
> 
> 
> tail -l /var/log/apache2/error.log
> [Wed Jun 13 15:46:22.636400 2018] [wsgi:error] [pid 2199] [client 
> 127.0.0.1:38068]     from flask import Flask
> [Wed Jun 13 15:46:22.636406 2018] [wsgi:error] [pid 2199] [client 
> 127.0.0.1:38068]   File 
> "/home/rajeev/anaconda3/lib/python3.6/site-packages/flask/__init__.py", line 
> 21, in <module>
> [Wed Jun 13 15:46:22.636409 2018] [wsgi:error] [pid 2199] [client 
> 127.0.0.1:38068]     from .app import Flask, Request, Response
> [Wed Jun 13 15:46:22.636413 2018] [wsgi:error] [pid 2199] [client 
> 127.0.0.1:38068]   File 
> "/home/rajeev/anaconda3/lib/python3.6/site-packages/flask/app.py", line 25, 
> in <module>
> [Wed Jun 13 15:46:22.636416 2018] [wsgi:error] [pid 2199] [client 
> 127.0.0.1:38068]     from . import cli, json
> [Wed Jun 13 15:46:22.636421 2018] [wsgi:error] [pid 2199] [client 
> 127.0.0.1:38068]   File 
> "/home/rajeev/anaconda3/lib/python3.6/site-packages/flask/cli.py", line 18, 
> in <module>
> [Wed Jun 13 15:46:22.636424 2018] [wsgi:error] [pid 2199] [client 
> 127.0.0.1:38068]     import ssl
> [Wed Jun 13 15:46:22.636429 2018] [wsgi:error] [pid 2199] [client 
> 127.0.0.1:38068]   File "/home/rajeev/anaconda3/lib/python3.6/ssl.py", line 
> 101, in <module>
> [Wed Jun 13 15:46:22.636432 2018] [wsgi:error] [pid 2199] [client 
> 127.0.0.1:38068]     import _ssl             # if we can't import it, let the 
> error propagate
> [Wed Jun 13 15:46:22.636453 2018] [wsgi:error] [pid 2199] [client 
> 127.0.0.1:38068] ImportError: 
> /home/rajeev/anaconda3/lib/python3.6/lib-dynload/_ssl.cpython-36m-x86_64-linux-gnu.so:
>  undefined symbol: SSLv2_method

When using Anaconda Python, you cannot used mod_ssl in Apache. This is because 
Anaconda Python ships its own SSL libraries which aren't compatible, and by 
having mod_ssl loaded, the system SSL libraries will get loaded first, 
resulting in any use of SSL in Python to fail.

If not using SSL in Apache, disable mod_ssl. If you are using it, the only way 
to do it is to use mod_wsgi-express to create a distinct instance and have the 
main Apache proxy to it.

> /var/www/FlaskApp/FlaskApp$ python __init__.py 
>  * Serving Flask app "__init__" (lazy loading)
>  * Environment: production
>    WARNING: Do not use the development server in a production environment.
>    Use a production WSGI server instead.
>  * Debug mode: off
>  * Running on http://127.0.0.1:5000/ <http://127.0.0.1:5000/> (Press CTRL+C 
> to quit)
> 127.0.0.1 - - [13/Jun/2018 15:48:53] "GET / HTTP/1.1" 200 -
> 127.0.0.1 - - [13/Jun/2018 15:48:53] "GET /favicon.ico HTTP/1.1" 404 -
> 
> Using browser on server (http://localhost:5000 <http://localhost:5000/>)is 
> able to load test page
> 
> This is where I am at...

After all that is addressed, we will see if any issues with permissions. That 
is, whether the Apache user can actually read everything in your home directory.

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 modwsgi+unsubscr...@googlegroups.com.
To post to this group, send email to modwsgi@googlegroups.com.
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to