Centos7 + php3.9.9 + apache failing

18 views
Skip to first unread message

matkatmusic

unread,
Dec 2, 2021, 4:42:56 PM12/2/21
to modwsgi
I am getting the following error when I try to use mod_wsgi with Apache2.4:

The “/usr/sbin/httpd -DSSL -t -f /etc/apache2/conf.d/includes/pre_main_global.conf.tmp.cfgcheck -C Include "/etc/apache2/conf.modules.d/*.conf"” command (process 10241) reported error number 1 when it ended. httpd: Syntax error on line 2 of /etc/apache2/conf.d/includes/pre_main_global.conf.tmp.cfgcheck: Cannot load modules/mod_wsgi.so into server: libpython3.9.so.1.0: cannot open shared object file: No such file or directory

I have installed python3.9.9 from source code as the Cpanel user into: $HOME/python/Python-3.9.9/
the configuration was:
--enable-shared --prefix=$HOME/python
This install location is taken from this tutorial from my host:

mkdir ~/python cd ~/python wget http://www.python.org/ftp/python/3.9.9/Python-3.9.9.tgz tar zxfv Python-3.9.9.tgz find ~/python -type d | xargs chmod 0755 cd Python-3.9.9
./configure --enable-shared --prefix=$HOME/python make make install

I have modified the CPanel user's .bashrc file to point to this location so that calling $ python -V will execute the python installed from source. 

This command failed (cannot find libpython3.9.so.1.0), so I followed the instructions here to add LD_LIBRARY_PATH to the .bashrc: 

export PATH=/home/bfxqsxmy/python/Python-3.9.9/:$PATH
export PATH=/home/bfxqsxmy/python/bin/:$PATH
export LD_LIBRARY_PATH=/home/bfxqsxmy/python/Python-3.9.9/:$LD_LIBRARY_PATH

Now running 'python -V' from the CPanel User's shell prints out 'python3.9.9'

I then installed mod_wsgi from source as the Cpanel user. 
the configuration used was:
./configure --with-apxs=/bin/apxs --with-python=/home/bfxqsxmy/python/Python-3.9.9/python

'make' succeeded without issue.
running 'make install' failed because I was the Cpanel user, and it was trying to write to /etc/apache2/modules/

running 'sudo make install' succeeded. 
/etc/apache2/modules/mod_wsgi.so now exists. 

Next: I try to edit the Apache Pre-main include file via WHM and add the following line:
 LoadModule wsgi_module modules/mod_wsgi.so

Updating the pre-main include file causes this error to appear: 
Error:
The “/usr/sbin/httpd -DSSL -t -f /etc/apache2/conf.d/includes/pre_main_global.conf.tmp.cfgcheck -C Include "/etc/apache2/conf.modules.d/*.conf"” command (process 10241) reported error number 1 when it ended. httpd: Syntax error on line 2 of /etc/apache2/conf.d/includes/pre_main_global.conf.tmp.cfgcheck: Cannot load modules/mod_wsgi.so into server: libpython3.9.so.1.0: cannot open shared object file: No such file or directory

Apache is running as the following users:
root (1 instance of /usr/sbin/httpd -k start)
nobody (6 instances of /usr/sbin/httpd -k start)

Any idea what the problem is? 

Thanks!!

Graham Dumpleton

unread,
Dec 2, 2021, 4:47:38 PM12/2/21
to mod...@googlegroups.com
A few quick comments as got other things need to do before read through this properly.

1. Compiling your own Python can be tricky. Read:


Ignore that it talks about docker as still relevant.

2. If you are using Python from a non standard location, if using CMMI install method you have to embed in mod_wsgi  knowledge of where it is. That is, set LD_RUN_PATH when compiling/installing module. Read:


3. Instead of using CMMI install method, it can be better to use pip install method. Read:


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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/a8bf68cd-491a-4ae4-be45-16f013eb6aa1n%40googlegroups.com.

matkatmusic

unread,
Dec 2, 2021, 9:18:27 PM12/2/21
to modwsgi
Success!!!

[wsgi:info] [pid 19919:tid 47035722368064] mod_wsgi (pid=19919): Initializing Python.
[Thu Dec 02 15:38:08.576095 2021] [wsgi:info] [pid 19916:tid 47035722368064] mod_wsgi (pid=19916): Attach interpreter ''.
[Thu Dec 02 15:38:08.586154 2021] [wsgi:info] [pid 19913:tid 47035722368064] mod_wsgi (pid=19913): Attach interpreter ''.
[Thu Dec 02 15:38:08.591026 2021] [wsgi:info] [pid 19914:tid 47035722368064] mod_wsgi (pid=19914): Attach interpreter ''.
[Thu Dec 02 15:38:08.594354 2021] [wsgi:info] [pid 19915:tid 47035722368064] mod_wsgi (pid=19915): Attach interpreter ''.
[Thu Dec 02 15:38:08.598385 2021] [wsgi:info] [pid 19919:tid 47035722368064] mod_wsgi (pid=19919): Attach interpreter ''.
[ N 2021-12-02 15:38:08.9955 19868/T1 age/Cor/TelemetryCollector.h:531 ]: Message from Phusion: End time can not be before or equal to begin time
[ N 2021-12-02 15:38:09.0274 19868/T1 age/Cor/CoreMain.cpp:1325 ]: Passenger core shutdown finished

Now I am getting python-specific errors when I try to load up my site.  
These errors are related to the virtual environment and the missing `activate_this.py` file. 

It seems like mod_wsgi is meant for, or designed around python v2.x, not v3.x 

I was able to get the hello, world snippet you shared here up and running and printing out. 

Now I just need to solve these import errors, which seem to be related to my folder hierarchy and file structure. 

Graham Dumpleton

unread,
Dec 2, 2021, 9:20:35 PM12/2/21
to mod...@googlegroups.com
You should not use activate_this.py for virtual environment activation unless you have no other choice. Use WSGIPythonHome or preferably use WSGIDaemonProcess and python-home as explain in that doc.

matkatmusic

unread,
Dec 2, 2021, 9:21:56 PM12/2/21
to modwsgi
I'm not using it. 
I followed your guide and what it says about python3. 

Graham Dumpleton

unread,
Dec 2, 2021, 9:23:41 PM12/2/21
to mod...@googlegroups.com
You would need to post the error messages and the mod_wsgi configuration if you want help resolving it. Too hard to guess otherwise.

matkatmusic

unread,
Dec 2, 2021, 9:42:15 PM12/2/21
to modwsgi
Here is the part that gets included automatically from the VirtualHost directive for my site http://flask.chordieapp.com
Cpanel is automatically creating the VirtualHost directive, and the instructions say to create a file in /etc/apache2/conf.d/userdata/ and then either /std/ or /ssl/ for the site that was added.
This is the http file:  /etc/apache2/conf.d/userdata/std/2_4/bfxqsxmy/flask.chordieapp.com/flask.chordieapp.com.conf

<IfModule alias_module>
WSGIDaemonProcess flaskapp python-home=/home/bfxqsxmy/public_html/flask/venv/
WSGIProcessGroup flaskapp
WSGIScriptAlias /app /home/bfxqsxmy/public_html/flask/application.wsgi
</IfModule>

<Directory "/home/bfxqsxmy/public_html/flask/">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>

# ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
# CustomLog ${APACHE_LOG_DIR}/access.log combined

Here is the https conf: 
<IfModule alias_module>
# this daemon process was declared in the /std/ copy of this file (handler for http, not https)
# WSGIDaemonProcess flaskapp python-home=/home/bfxqsxmy/public_html/flask/venv/
WSGIProcessGroup flaskapp
WSGIScriptAlias /app /home/bfxqsxmy/public_html/flask/application.wsgi
</IfModule>

<Directory "/home/bfxqsxmy/public_html/flask/">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>

# ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
# CustomLog ${APACHE_LOG_DIR}/access.log combined

Here is the folder hierarchy over /public_html/flask
Screen Shot 2021-12-02 at 6.36.04 PM.png
Here is the folder hierarchy of /public_html/flask/pfm/
Screen Shot 2021-12-02 at 6.33.44 PM.png

Here is what is written in `application.wsgi`:
1 python_home = '/home/bfxqsxmy/public_html/flask/venv'
2 import sys
3 import site
4
5 # Calculate path to site-packages directory.
6
7 python_version = '.'.join(map(str, sys.version_info[:2]))
8 site_packages = python_home + '/lib/python%s/site-packages' % python_version
9
10 # Add the site-packages directory.
11
12 site.addsitedir(site_packages)
13 from pfm import test1 as test1
14 from test1 import app as application

Here's the error message: _wsgi (pid=13119, process='flaskapp', application='flask.chordieapp.com|/app'): Loading Python script file '/home/bfxqsxmy/public_html/flask/application.wsgi'. [Thu Dec 02 19:37:30.512141 2021] [wsgi:error] [pid 13119:tid 47096016185088] [remote 73.221.155.223:57349] mod_wsgi (pid=13119): Failed to exec Python script file '/home/bfxqsxmy/public_html/flask/application.wsgi'. [Thu Dec 02 19:37:30.512220 2021] [wsgi:error] [pid 13119:tid 47096016185088] [remote 73.221.155.223:57349] mod_wsgi (pid=13119): Exception occurred processing WSGI script '/home/bfxqsxmy/public_html/flask/application.wsgi'. [Thu Dec 02 19:37:30.512623 2021] [wsgi:error] [pid 13119:tid 47096016185088] [remote 73.221.155.223:57349] Traceback (most recent call last): [Thu Dec 02 19:37:30.512660 2021] [wsgi:error] [pid 13119:tid 47096016185088] [remote 73.221.155.223:57349]File "/home/bfxqsxmy/public_html/flask/application.wsgi", line 13, in <module> [Thu Dec 02 19:37:30.512664 2021] [wsgi:error] [pid 13119:tid 47096016185088] [remote 73.221.155.223:57349] from pfm import test1 as test1 [Thu Dec 02 19:37:30.512690 2021] [wsgi:error] [pid 13119:tid 47096016185088] [remote 73.221.155.223:57349] ModuleNotFoundError: No module named 'pfm'


When I comment everything out in application.wsgi and use your 'hello world' script instead, I see 'hello world' when I visit the URL to the app: 
def application(environ, start_response):
status = '200 OK'
output = b'Hello World!'

response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output]

Screen Shot 2021-12-02 at 6.22.48 PM.png

As I said earlier, it's a python error related to the folder hierarchy and not being able to find the files. 
Any ideas?

Graham Dumpleton

unread,
Dec 2, 2021, 10:09:34 PM12/2/21
to mod...@googlegroups.com

On 3 Dec 2021, at 1:42 pm, matkatmusic <matka...@gmail.com> wrote:

Here is the part that gets included automatically from the VirtualHost directive for my site http://flask.chordieapp.com
Cpanel is automatically creating the VirtualHost directive, and the instructions say to create a file in /etc/apache2/conf.d/userdata/ and then either /std/ or /ssl/ for the site that was added.
This is the http file:  /etc/apache2/conf.d/userdata/std/2_4/bfxqsxmy/flask.chordieapp.com/flask.chordieapp.com.conf

<IfModule alias_module>

There shouldn't be an IfModule section for alias_module because that is nothing to do with mod_wsgi. You only want what was inside that section.

WSGIDaemonProcess flaskapp python-home=/home/bfxqsxmy/public_html/flask/venv/
WSGIProcessGroup flaskapp
WSGIScriptAlias /app /home/bfxqsxmy/public_html/flask/application.wsgi

Better to also change this to:

        WSGIDaemonProcess flaskapp python-home=/home/bfxqsxmy/public_html/flask/venv/
        WSGIScriptAlias /app /home/bfxqsxmy/public_html/flask/application.wsgi process-group=flaskapp application-group=%{GLOBAL}

You are also not telling mod_wsgi where you application code is. You probably mean:

        WSGIDaemonProcess flaskapp python-home=/home/bfxqsxmy/public_html/flask/venv/ python-path=/home/bfxqsxmy/public_html/flask
        WSGIScriptAlias /app /home/bfxqsxmy/public_html/flask/application.wsgi process-group=flaskapp application-group=%{GLOBAL}

</IfModule>

<Directory "/home/bfxqsxmy/public_html/flask/">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>

# ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
# CustomLog ${APACHE_LOG_DIR}/access.log combined

Here is the https conf: 
<IfModule alias_module>
# this daemon process was declared in the /std/ copy of this file (handler for http, not https)
# WSGIDaemonProcess flaskapp python-home=/home/bfxqsxmy/public_html/flask/venv/
WSGIProcessGroup flaskapp
WSGIScriptAlias /app /home/bfxqsxmy/public_html/flask/application.wsgi
</IfModule>

<Directory "/home/bfxqsxmy/public_html/flask/">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>

# ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
# CustomLog ${APACHE_LOG_DIR}/access.log combined

Only need for mod_wsgi.

        WSGIScriptAlias /app /home/bfxqsxmy/public_html/flask/application.wsgi process-group=flaskapp application-group=%{GLOBAL}

No WSGIDaemonProcess directive.

You still need the Directory stuff in both.

Here is the folder hierarchy over /public_html/flask
<Screen Shot 2021-12-02 at 6.36.04 PM.png>
Here is the folder hierarchy of /public_html/flask/pfm/
<Screen Shot 2021-12-02 at 6.33.44 PM.png>

Here is what is written in `application.wsgi`:
1 python_home = '/home/bfxqsxmy/public_html/flask/venv'
2 import sys
3 import site
4
5 # Calculate path to site-packages directory.
6
7 python_version = '.'.join(map(str, sys.version_info[:2]))
8 site_packages = python_home + '/lib/python%s/site-packages' % python_version
9
10 # Add the site-packages directory.
11
12 site.addsitedir(site_packages)
13 from pfm import test1 as test1
14 from test1 import app as application

This should all be replaced with just:

    from pfm import test1 as test1
    from test1 import app as application

The directory that "pfm" package is in should be what you add to python-path above.


Here's the error message: _wsgi (pid=13119, process='flaskapp', application='flask.chordieapp.com|/app'): Loading Python script file '/home/bfxqsxmy/public_html/flask/application.wsgi'. [Thu Dec 02 19:37:30.512141 2021] [wsgi:error] [pid 13119:tid 47096016185088] [remote 73.221.155.223:57349] mod_wsgi (pid=13119): Failed to exec Python script file '/home/bfxqsxmy/public_html/flask/application.wsgi'. [Thu Dec 02 19:37:30.512220 2021] [wsgi:error] [pid 13119:tid 47096016185088] [remote 73.221.155.223:57349] mod_wsgi (pid=13119): Exception occurred processing WSGI script '/home/bfxqsxmy/public_html/flask/application.wsgi'. [Thu Dec 02 19:37:30.512623 2021] [wsgi:error] [pid 13119:tid 47096016185088] [remote 73.221.155.223:57349] Traceback (most recent call last): [Thu Dec 02 19:37:30.512660 2021] [wsgi:error] [pid 13119:tid 47096016185088] [remote 73.221.155.223:57349]File "/home/bfxqsxmy/public_html/flask/application.wsgi", line 13, in <module> [Thu Dec 02 19:37:30.512664 2021] [wsgi:error] [pid 13119:tid 47096016185088] [remote 73.221.155.223:57349] from pfm import test1 as test1 [Thu Dec 02 19:37:30.512690 2021] [wsgi:error] [pid 13119:tid 47096016185088] [remote 73.221.155.223:57349] ModuleNotFoundError: No module named 'pfm'


When I comment everything out in application.wsgi and use your 'hello world' script instead, I see 'hello world' when I visit the URL to the app: 
def application(environ, start_response):
status = '200 OK'
output = b'Hello World!'

response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output]

To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/dc970e73-cada-423e-97c3-1f463120c12fn%40googlegroups.com.
<Screen Shot 2021-12-02 at 6.22.48 PM.png><Screen Shot 2021-12-02 at 6.33.44 PM.png><Screen Shot 2021-12-02 at 6.36.04 PM.png>

matkatmusic

unread,
Dec 2, 2021, 11:35:45 PM12/2/21
to modwsgi
Alright, I got it fully working now.

I had to use this in the conf files:
WSGIDaemonProcess flaskapp python-home=/home/bfxqsxmy/public_html/flask/venv/ python-path=/home/bfxqsxmy/public_html/flask/
WSGIScriptAlias /app /home/bfxqsxmy/public_html/flask/application.wsgi process-group=flaskapp application-group=%{GLOBAL}

And then this in the application.wsgi file
from pfm.test1 import app as application

Now I can try migrating the actual app over, including the .env file, and seeing if it works.

matkatmusic

unread,
Dec 2, 2021, 11:36:55 PM12/2/21
to modwsgi
Thank you for your help, by the way!

Graham Dumpleton

unread,
Dec 2, 2021, 11:44:34 PM12/2/21
to mod...@googlegroups.com
Apache will not use per user environment settings. So if that .env file is something set in shell you can't use it. You will need to use some means for the Python code to read the .env file direct.

Matkat Music

unread,
Dec 3, 2021, 2:09:49 AM12/3/21
to mod...@googlegroups.com
I'm using the dotenv module actually.  It's very handy

from dotenv import load_dotenv
load_dotenv()

You received this message because you are subscribed to a topic in the Google Groups "modwsgi" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/modwsgi/6V7Ueg8phZA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to modwsgi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/6D874695-BDB4-4C5F-947E-137DDB250FDE%40gmail.com.

Graham Dumpleton

unread,
Dec 3, 2021, 2:20:04 AM12/3/21
to mod...@googlegroups.com
Figured you might, but wanted to make sure. :-)

Reply all
Reply to author
Forward
0 new messages