SOLVED: 

-I had virtual environment inside my home folder. That's a 'no no' unless I 
grant apache access into my home folder's environment directory. Did not 
want to do that so I created a virtual environment inside my application 
folder (see 'env' in the output)
-Because of that ^, I was needing to do 'sudo pip install flask' and sudo 
pip install mod-wsgi'. That's a big security 'no no'. This was giving me 
grief for days. Thank you, Graham Dumpleton for all your help!!! 

Here's my configuration as it might help others:



[myuser@centosnew myflaskapp]$ ls -lhi
total 12K
    6397 drwxr-xr-x 5 mysuser myuser 100 Jul 19 18:09 env
    6383 -rwxr-xr-x 1 mysuser myuser 949 Jul 23 15:30 __init__.py
13677487 drwxr-xr-x 2 mysuser myuser  43 Jul 15 16:52 logs
    6378 -rwxr-xr-x 1 mysuser myuser  97 Jul 23 12:17 myflaskapp.wsgi
 9011898 drwxrwxr-x 2 mysuser myuser  42 Jul 23 08:56 __pycache__
 4729228 drwxr-xr-x 2 mysuser myuser   6 Jul 12 08:06 static
 8885310 drwxr-xr-x 2 mysuser myuser 104 Jul 23 15:19 templates
[myuser@centosnew myflaskapp]$ pwd
/var/www/myflaskapp/myflaskapp <<<<<<THIS IS MY APPLICATION FOLDER ^
[myuser@centosnew myflaskapp]$

Here is my site configuration in the apache config file. Note that the 
'LoadModule command is not inside the VirtualHost section. It's in the 
specific location I show:

LOOK FOR THIS SECTION IN THE APACHE CONFIG FILE:

# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO 
you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#
Include conf.modules.d/*.conf
#
#THIS NEXT LINE IS WHAT MAKES APACHE LOAD THE MOD_WSGI MODULE THAT 'LIVES' 
IN THE VIRTUAL ENVIRONMENT

LoadModule wsgi_module 
/var/www/myflaskapp/myflaskapp/env/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so

#THIS NEXT SECTION IS ADDED TO THE END OF THE FILE


<VirtualHost *:80>

    ServerName myserver.myflaskapp.com
    #ServerAlias www.myflaskapp.com
    DocumentRoot /var/www/myflaskapp
    WSGIDaemonProcess myflaskapp processes=2 threads=15 
python-home=/var/www/myflaskapp/myflaskapp/env 
python-path=/var/www/myflaskapp/myflaskapp/env
    WSGIScriptAlias / /var/www/myflaskapp/myflaskapp/myflaskapp.wsgi
    WSGIApplicationGroup %{GLOBAL}

    <Directory /var/www/myflaskapp/myflaskapp>
        WSGIProcessGroup myflaskapp
        WSGIApplicationGroup %{GLOBAL}
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/www/myflaskapp/myflaskapp/logs/error.log
    CustomLog /var/www/myflaskapp/myflaskapp/logs/requests.log combined
</VirtualHost>

This is what myflaskapp.wsgi file contains:

import sys

sys.path.insert(0, "/var/www/myflaskapp")

from myflaskapp import app as application

This is some output about the virtual environment. IMPORTANT - mod-wsgi 
must be installed inside the virtual environment with the virtual 
environment active. Once installed, you deactivate the virtual environment. 
In this output I am just illustrating how I get into the virtual 
environment to see what python modules are installed in it. Then, I just 
deactivate it as apache does NOT need the environment to be active in order 
to use the module. 

[myuser@centosnew myflaskapp]$ source 
/var/www/myflaskapp/myflaskapp/env/bin/activate <<<<<THIS ACTIVATES THE 
ENVIRONMENT
(env) [gera@centosnew myflaskapp]$
(env) [myuser@centosnew myflaskapp]$ which pip
/var/www/myflaskapp/myflaskapp/env/bin/pip
(env) [myuser@centosnew myflaskapp]$ pip list
Package      Version
------------ ---------
certifi      2018.4.16
chardet      3.0.4
click        6.7
Flask        1.0.2
idna         2.7
itsdangerous 0.24
Jinja2       2.10
MarkupSafe   1.0
mod-wsgi     4.6.4
pip          18.0
requests     2.19.1
setuptools   39.0.1
urllib3      1.23
Werkzeug     0.14.1
(env) [myuser@centosnew myflaskapp]$ deactivate
[myuser@centosnew myflaskapp]$





On Wednesday, July 11, 2018 at 4:45:27 PM UTC-7, jerry100 wrote:
>
> Hello all! The requests module was installed in the site-packages folder 
> in the virtual environment as I expected. I ran "pip install requests". 
> Since I run the flask app on apache and the virtual environment is 
> inactive, by design, as we are using mod_wsgi, the requests module is not 
> being imported by Apache.
>
> /var/www/mywebsite.com/flask/lib/python3.6/site-packages/requests
>
> This is how I am trying to import the module:
>
> from flask import Flask, render_template, request
> import requests
>
>
> Here's my flask.wsgi file. Are we supposed to import modules in this file 
> instead of init.py file?
>
> import sys
>
> sys.path.insert(0, "/var/www/mywebsite.com/flask/")
>
> from init import app as application
>
>
> This is the error I get. What am I doing wrong?
>
> [Wed Jul 11 16:16:18.941771 2018] [wsgi:error] [pid 7244] [client 192.168.
> 1.2:64794] Traceback (most recent call last):
> [Wed Jul 11 16:16:18.941850 2018] [wsgi:error] [pid 7244] [client 192.168.
> 1.2:64794]   File "/var/www/mywebsite.com/flask/flask.wsgi", line 5, in 
> <module>
> [Wed Jul 11 16:16:18.941864 2018] [wsgi:error] [pid 7244] [client 192.168.
> 1.2:64794]     from init import app as application
> [Wed Jul 11 16:16:18.941876 2018] [wsgi:error] [pid 7244] [client 192.168.
> 1.2:64794]   File "/var/www/mywebsite.com/flask/init.py", line 2, in 
> <module>
> [Wed Jul 11 16:16:18.941881 2018] [wsgi:error] [pid 7244] [client 192.168.
> 1.2:64794]     import requests
> [Wed Jul 11 16:16:18.941909 2018] [wsgi:error] [pid 7244] [client 192.168.
> 1.2:64794] ModuleNotFoundError: No module named 'requests'
>

-- 
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