I am trying to get mod_wsgi working with Apache 2.4.6 on RHEL.  I have 
access to the sudo command but not root.  

The net-net: No matter what I have tried, I can not get mod_wsgi to see the 
associated python modules for the virtual environment that it was 
configured for using Anaconda 3.  

The good news: According to the Apache error log files, mod_wsgi has loaded 
successfully.
The bad news is that I receive numerous messages: Fatal Python error: 
Py_Initialize: Unable to get the locale encoding ModuleNotFoundError: No 
module named 'encodings'

I've spent two days trying what I believe is every combination of 
configurations I've seen from the various posts I've read on virtual 
environments, all to no avail.

I even pasting the output of mod_wsgi module-config into the httpd.conf 
file.  The LoadModule statement fails with a permissions error even though 
all of the files in the entire directory have been set to 777.

The only way I have been able to get the mod_wsgi module to load has been 
to:
1. Build mod_wsgi from source in the virtual environment of my application
2. Use the make install command to load the module into the apache modules 
directory
3. Copy the libpython3.6m.so.1.0 directly into the /usr/lib64 directory 
(allows mod_wsgi.so to see it).

But still, I get the ModuleNotFoundError: No module named 'encodings' 
message

I'd really appreciate some help.  Here's the state of my configuration:

*Here is a section of the Apache Error Log:*

[Fri Apr 05 14:56:25.878394 2019] [core:notice] [pid 4621] SELinux policy 
enabled; httpd running as context system_u:system_r:httpd_
t:s0
[Fri Apr 05 14:56:25.879482 2019] [suexec:notice] [pid 4621] AH01232: 
suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Fri Apr 05 14:56:25.898250 2019] [auth_digest:notice] [pid 4621] AH01757: 
generating secret for digest authentication ...
[Fri Apr 05 14:56:25.899292 2019] [lbmethod_heartbeat:notice] [pid 4621] 
AH02282: No slotmem from mod_heartmonitor
[Fri Apr 05 14:56:25.900426 2019] [wsgi:info] [pid 4622] mod_wsgi 
(pid=4622): Starting process 'ImgOrientD' with uid=48, gid=48 and
threads=15.
[Fri Apr 05 14:56:25.901434 2019] [wsgi:info] [pid 4622] mod_wsgi 
(pid=4622): Python home /home/pboerner/.conda/envs/imgorient.
[Fri Apr 05 14:56:25.901496 2019] [wsgi:info] [pid 4622] mod_wsgi 
(pid=4622): Initializing Python.
[Fri Apr 05 14:56:25.901909 2019] [wsgi:info] [pid 4623] mod_wsgi 
(pid=4623): Initializing Python.
[Fri Apr 05 14:56:25.902368 2019] [mpm_prefork:notice] [pid 4621] AH00163: 
Apache/2.4.6 (Red Hat Enterprise Linux) mod_wsgi/4.6.5 Py
thon/3.6 configured -- resuming normal operations
[Fri Apr 05 14:56:25.902391 2019] [mpm_prefork:info] [pid 4621] AH00164: 
Server built: Jun 22 2018 01:19:25
[Fri Apr 05 14:56:25.902403 2019] [core:notice] [pid 4621] AH00094: Command 
line: '/usr/sbin/httpd -D FOREGROUND'
[Fri Apr 05 14:56:25.902778 2019] [wsgi:info] [pid 4625] mod_wsgi 
(pid=4625): Initializing Python.
[Fri Apr 05 14:56:25.903619 2019] [wsgi:info] [pid 4627] mod_wsgi 
(pid=4627): Initializing Python.
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

*The Apache configuration:*

Server version: Apache/2.4.6 (Red Hat Enterprise Linux)
Server built:   Jun 22 2018 01:19:25
Server's Module Magic Number: 20120211:24
Server loaded:  APR 1.4.8, APR-UTIL 1.5.2
Compiled using: APR 1.4.8, APR-UTIL 1.5.2
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="/run/httpd/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

*The httpd.conf file for apache:*
LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so

# Configure the virtual host for mod_wsgi which will run the MLAI code

<VirtualHost *:80>
    ServerName duaidapst01
    # Set up a daemon process 
    WSGIDaemonProcess ImgOrientD 
python-home=/home/pboerner/.conda/envs/imgorient
    # Now make sure this runs within that process group
    WSGIProcessGroup ImgOrientD
    WSGIApplicationGroup %{GLOBAL}
    WSGIScriptAlias /mlai_test /var/www/wsgi-scripts/mlai_test.wsgi
    <Directory /var/www/wsgi-scripts>
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

*My simple python wsgi code to test (this never runs):*

ALLDIRS = 
['/home/pboerner/.conda/envs/imgorient/lib/python3.6/site-packages']
import sys
import site
# Remember original sys.path.
prev_sys_path = list(sys.path)
# Add each new site-packages directory.
for directory in ALLDIRS:
    site.addsitedir(directory)
# Reorder sys.path so new directories at the front.
new_sys_path = []
for item in list(sys.path):
    if item not in prev_sys_path:
    new_sys_path.append(item)
    sys.path.remove(item)
sys.path[:0] = new_sys_path

def application(environ, start_response):
    ex = sys.executable
    status = '200 OK'
    output = "Executable: {} ".format(ex)
    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]


Many, many thanks for any help this community can provide!!

Peer

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