Closed anubhaw2091 closed 6 years ago
When building mod_wsgi from source code, set the LD_RUN_PATH
environment variable and export it.
LD_RUN_PATH=/root/anaconda3/lib
It only needs to be set when building it.
You will also need to set:
WSGIPythonHome /root/anaconda3
in the Apache configuration.
Better than the way you are installing it, is to use pip
to install it.
pip install mod_wsgi
Then run:
mod_wsgi-express module-config
That will output the config for you to add to the Apache configuration.
Do be aware that Anaconda Python cannot be used if you want to use mod_ssl in Apache. This is because Anaconda Python ships with its own SSL libraries that are incompatible with system SSL libraries and mod_ssl witll pull in system libraries first, resulting in anything in the Python application using SSL not working.
I uninstalled mod_wsgi
and then removed the lines which I added in httpd
conf file. Later I removed the env variables too.
As suggested by you, I ran pip install mod_wsgi
After that
[root@redhat opt]# mod_wsgi-express module-config
LoadModule wsgi_module "/root/anaconda3/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
WSGIPythonHome "/root/anaconda3"
[root@redhat opt]# httpd -t
Syntax OK
[root@redhat opt]# service httpd restart
Redirecting to /bin/systemctl restart httpd.service
I also added the following line in httpd
conf file.
#added by anubhaw
#LoadModule wsgi_module /etc/httpd/modules/mod_wsgi.so
LoadModule wsgi_module "/root/anaconda3/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
WSGIPythonHome "/root/anaconda3"
#add end
But now am getting error in var/log/httpd/error_log
file.
Current thread 0x00007fba735e9880 (most recent call first):
[Fri Dec 15 00:45:52.621623 2017] [wsgi:warn] [pid 28077] (13)Permission denied: mod_wsgi (pid=28077): Unable to stat Python home /root/anaconda3. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path.
[Fri Dec 15 00:45:52.627745 2017] [core:notice] [pid 28029] AH00052: child pid 28072 exit signal Aborted (6)
[Fri Dec 15 00:45:52.627780 2017] [core:notice] [pid 28029] AH00052: child pid 28073 exit signal Aborted (6)
[Fri Dec 15 00:45:52.627786 2017] [core:notice] [pid 28029] AH00052: child pid 28074 exit signal Aborted (6)
[Fri Dec 15 00:45:52.627793 2017] [core:notice] [pid 28029] AH00052: child pid 28075 exit signal Aborted (6)
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007fba735e9880 (most recent call first):
[Fri Dec 15 00:45:52.628807 2017] [wsgi:warn] [pid 28078] (13)Permission denied: mod_wsgi (pid=28078): Unable to stat Python home /root/anaconda3. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path.
[Fri Dec 15 00:45:52.630296 2017] [wsgi:warn] [pid 28081] (13)Permission denied: mod_wsgi (pid=28081): Unable to stat Python home /root/anaconda3. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path.
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
The directory /root/anaconda3
is likely not accessible to anyone except the root
user.
Generally it is a bad idea to install stuff under /root
. That is the home directory for the root
account and normal users wouldn't be able to access it.
Let's say for testing purpose I give all the permission to root
folder. How do I do it? What permission should I give it?
Current situation :
[root@redhat ~]# ls -ld /root/anaconda3/
drwxr-xr-x. 22 root root 4096 Dec 14 11:47 /root/anaconda3/
Maybe once I get it up and running, I will install anaconda in /opt
folder and repeat the whole process.
Giving access to /root/anaconda3/
is not enough. The problem is the /root
directory. Your should really install it under /opt
instead from outset otherwise nothing besides root
can use it.
Being under /root
, you could also be blocked from access it as Apache user due to SELinux setup.
Ohh. Let me repeat the whole thing after installing anaconda in /opt
folder and get back to you.
Thanks for prompt responses. :)
I installed anaconda
in /opt/anaconda3
.
After that I removed mod_wsgiusing
pip uninstall mod_wsgi`
After that I installed mod_wsgi
[root@redhat ~]# pip install mod_wsgi
Collecting mod_wsgi
Installing collected packages: mod-wsgi
Successfully installed mod-wsgi-4.5.23
[root@redhat ~]# mod_wsgi-express module-config
LoadModule wsgi_module "/opt/anaconda3/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
WSGIPythonHome "/opt/anaconda3"
[root@redhat ~]# service httpd stop
Redirecting to /bin/systemctl stop httpd.service
[root@redhat ~]# service httpd start
Redirecting to /bin/systemctl start httpd.service
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
[root@redhat ~]# httpd -t
httpd: Syntax error on line 59 of /etc/httpd/conf/httpd.conf: Cannot load /opt/anaconda3/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so into server: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory
I already added the following line in http
conf file.
#added by anubhaw
#LoadModule wsgi_module /etc/httpd/modules/mod_wsgi.so
LoadModule wsgi_module "/opt/anaconda3/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
WSGIPythonHome "/opt/anaconda3"
#add end
Going by the error which am getting, I should compile the mod_wsgi with the python version which I use. So basically am again back to square one. :(
Because you moved where Anaconda was installed, you must make sure you do not use the cached build of mod_wsgi. Try:
pip install --no-cache-dir mod_wsgi
I uninstalled anaconda using below codes. (Got it on Stack)
conda install anaconda-clean # install the package anaconda clean
anaconda-clean --yes # clean all anaconda related files and directories
rm -rf ~/anaconda3 # removes the entire anaconda directory
rm -rf ~/.anaconda_backup # anaconda clean creates a back_up of files/dirs, remove it
# (conda list; cmd shouldn't respond after the clean up)
But pip install --no-cache-dir mod_wsgi
did the trick.
Got AH00163: Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips PHP/5.4.16 mod_wsgi/4.5.23 Python/3.6 configured -- resuming normal operations
in error log.
Thanks a ton. Now I'll try to run a flask application.
One more question : I have a situation in which I can't use pip install mod_wsgi
due to company policy. Because of that I copied the tar file and then installed in using make install
. How do I make it work in that situation?
The cache for pip
is in your home directory so removing and reinstalling Anaconda Python wouldn't have made a difference.
Instructions for the configure/make/make install method installation are found in:
The issue with shared library not being found is mentioned in:
You need to set the LD_RUN_PATH
environment variable to library directory where Anaconda Python shared library is. Also set WSGIPythonHome
to be what sys.prefix
gives for Anaconda Python.
I already mentioned LD_RUN_PATH
and WSGIPythonHome
above.
The reason things weren't working before for you with that would have been because you had things under /root
.
Thanks. Will try that and update for the same.
Thanks a lot.
So I need to reopen this issue.
I again ran into a situation where I don't have internet connection and mod_wsgi is just not getting installed.
Steps which I took.
/opt/Anaconda
mod_wsgi
from https://pypi.python.org/pypi/mod_wsgi
Loading Module Into Apache
part. In the httpd config file, there is a line Include conf.modules.d/*.conf
on line number 56 and in conf.modules.d
folder, I have a file named 10-wsgi.conf
after installing mod-wsgi whose content are as follows,LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so
So basically I didn't need to additionally add the LoadModule wsgi_module modules/mod_wsgi.so
into the httpd conf file. (Although I tried adding that, didn't change the problem).
/usr/lib64/httpd/modules
folder.[root@demoDB ~]# cd /usr/lib64/httpd/modules
[root@demoDB modules]# ldd mod_wsgi.so
linux-vdso.so.1 => (0x00007ffce896e000)
libpython3.6m.so.1.0 => /opt/Anaconda/lib/libpython3.6m.so.1.0 (0x00007f53c04ba000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f53c0296000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f53c0092000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007f53bfe8f000)
librt.so.1 => /lib64/librt.so.1 (0x00007f53bfc86000)
libm.so.6 => /lib64/libm.so.6 (0x00007f53bf984000)
libc.so.6 => /lib64/libc.so.6 (0x00007f53bf5c1000)
/lib64/ld-linux-x86-64.so.2 (0x0000560e483ea000)
[root@demoDB modules]#
I can see the libpython3.6m.so.1.0
path. The file is there.
[root@demoDB modules]# httpd -t
Syntax OK
[root@demoDB modules]# service httpd stop
Redirecting to /bin/systemctl stop httpd.service
[root@demoDB modules]# service httpd start
Redirecting to /bin/systemctl start httpd.service
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
[root@demoDB modules]#
journalctl -xe
to see the issue and I get this,-- Unit httpd.service has begun starting up.
Mar 08 14:45:14 demoDB.cat-api.com httpd[2244]: httpd: Syntax error on line 56 of /etc/httpd/conf/httpd.conf: Syntax error on line 1 of /etc/httpd/conf.modules.d/10-wsgi.conf: Cannot load /usr/lib64/httpd/modules/mod_wsgi.so into server: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory
Mar 08 14:45:14 demoDB.cat-api.com systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Mar 08 14:45:14 demoDB.cat-api.com kill[2245]: kill: cannot find process ""
Mar 08 14:45:14 demoDB.cat-api.com systemd[1]: httpd.service: control process exited, code=exited status=1
Mar 08 14:45:14 demoDB.cat-api.com systemd[1]: Failed to start The Apache HTTP Server.
-- Subject: Unit httpd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit httpd.service has failed.
I also set the LD_LIBRARY_PATH
and LD_RUN_PATH
[root@demoDB modules]# echo $LD_LIBRARY_PATH
/opt/Anaconda/lib
[root@demoDB modules]# echo $LD_RUN_PATH
/opt/Anaconda/lib
[root@demoDB modules]#
So basically I tried everything as suggested but am not able to get it working.
I tried referring to the conf file of the server where I installed it using pip, and it was fairly simple( although I don't get the same structure of mod_wsgi folder inside anaconda.
LoadModule wsgi_module "/opt/anaconda3/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
WSGIPythonHome "/opt/anaconda3"
Any help will be appreciated.
Thanks.
You can't have set and exported the LD_RUN_PATH
environment variable when building mod_wsgi.
make distclean
./configure --with-python /opt/Anaconda/bin/python
LD_RUN_PATH=/opt/Anaconda/lib make
make install
So I am setting LD_RUN_PATH
on the same line as the make command.
Alternatively use:
LD_RUN_PATH=/opt/Anaconda/lib
export LD_RUN_PATH
make
Do not set LD_LIBRARY_PATH
as it will confuse things when you run ldd
to check that the shared library is found. You only need to set LD_RUN_PATH
for doing the build.
As I said before, using the pip install
method may be better as it should ensure LD_RUN_PATH
is set for the build automatically.
If all else fails, add before the LoadModule
line:
LoadFile /opt/Anaconda/lib/libpython3.6m.so.1.0
Sorry for replying late.
So I followed your instruction and this is what I did.( For future reference for others.)
Unset the Variables.
[root@demoDB mod_wsgi-4.6.2]# make distclean
Then ./configure
[root@demoDB mod_wsgi-4.6.2]# ./configure
checking for apxs2... no
checking for apxs... /usr/bin/apxs
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for prctl... yes
checking Apache version... 2.4.6
checking for python... /opt/Anaconda/bin/python
configure: creating ./config.status
config.status: creating Makefile
I tried your way i.e `./configure --python /opt/Anaconda/bin/python` but that gave me an error i.e
[root@demoDB mod_wsgi-4.6.2]# ./configure --with-python /opt/Anaconda/bin/python
configure: WARNING: you should use --build, --host, --target
configure: WARNING: invalid host type: /opt/Anaconda/bin/python
checking for apxs2... no
checking for apxs... /usr/bin/apxs
checking for /opt/Anaconda/bin/python-gcc... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for prctl... yes
checking Apache version... 2.4.6
yes: invalid option -- 'c'
Try 'yes --help' for more information.
yes: invalid option -- 'c'
Try 'yes --help' for more information.
yes: invalid option -- 'c'
Try 'yes --help' for more information.
yes: invalid option -- 'c'
Try 'yes --help' for more information.
yes: invalid option -- 'c'
Try 'yes --help' for more information.
yes: invalid option -- 'c'
Try 'yes --help' for more information.
yes: invalid option -- 'c'
Try 'yes --help' for more information.
yes: invalid option -- 'c'
Try 'yes --help' for more information.
yes: invalid option -- 'c'
Try 'yes --help' for more information.
yes: invalid option -- 'c'
Try 'yes --help' for more information.
yes: invalid option -- 'c'
Try 'yes --help' for more information.
configure: creating ./config.status
config.status: creating Makefile
[root@demoDB mod_wsgi-4.6.2]# LD_RUN_PATH=/opt/Anaconda/lib make
/usr/bin/apxs -c -Wc,-g -Wc,-O2 src/server/modwsgi.c src/server/wsgi*.c -L -L -lpython
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
/usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -std=gnu99 -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -DLINUX -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd -I/usr/include/apr-1 -I/usr/include/apr-1 -g -O2 -c -o src/server/mod_wsgi.lo src/server/mod_wsgi.c && touch src/server/mod_wsgi.slo
In file included from src/server/mod_wsgi.c:22:0:
src/server/wsgi_python.h:24:20: fatal error: Python.h: No such file or directory
^
compilation terminated. apxs:Error: Command failed with rc=65536 . make: *** [src/server/mod_wsgi.la] Error 1
After that I did
[root@demoDB mod_wsgi-4.6.2]# LD_RUN_PATH=/opt/Anaconda/lib make
Then installed it with `[root@demoDB mod_wsgi-4.6.2]# make install`.
In the httpd error log file, I got `[Sun Mar 11 07:03:29.112855 2018] [mpm_prefork:notice] [pid 5824] AH00163: Apache/2.4.6 (Red Hat Enterprise Linux) mod_wsgi/4.6.2 Python/3.6 configured -- resuming normal operations`
I think it got configured properly but I ran into another problem which I can't figure out.
I need to run the flask application so I added `WSGIPythonHome "/opt/anaconda3"` in the httpd conf file.
But when am trying to start the application am getting the following error.
Current thread 0x00007ff3616bd880 (most recent call first): [Sun Mar 11 07:03:29.180630 2018] [core:notice] [pid 5824] AH00052: child pid 5825 exit signal Aborted (6) [Sun Mar 11 07:03:29.181356 2018] [core:notice] [pid 5824] AH00052: child pid 5826 exit signal Aborted (6) [Sun Mar 11 07:03:29.181392 2018] [core:notice] [pid 5824] AH00052: child pid 5827 exit signal Aborted (6) [Sun Mar 11 07:03:29.181409 2018] [core:notice] [pid 5824] AH00052: child pid 5828 exit signal Aborted (6) [Sun Mar 11 07:03:29.181424 2018] [core:notice] [pid 5824] AH00052: child pid 5829 exit signal Aborted (6) [Sun Mar 11 07:03:29.181455 2018] [core:notice] [pid 5824] AH00052: child pid 5830 exit signal Aborted (6) [Sun Mar 11 07:03:29.182657 2018] [wsgi:warn] [pid 5831] (2)No such file or directory: mod_wsgi (pid=5831): Unable to stat Python home /opt/anaconda3. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path. Fatal Python error: Py_Initialize: Unable to get the locale encoding ModuleNotFoundError: No module named 'encodings'
Now I tried stack [https://stackoverflow.com/questions/24495348/mod-wsgi-importerror-no-module-named-encodings](url)
Based on the first answer, I tried checking my folder permission list.
Structure is `var/www/sampleDashboard`
Inside sampleDashboard I have a `sample.wsgi` and `sampleDashboard` folder which contains all the files.
[root@demoDB www]# ls -l total 12 drwxr-xr-x. 2 root root 4096 Oct 3 08:37 cgi-bin drwxr-xr-x. 2 root root 4096 Oct 3 08:37 html drwxr-xr-x. 3 root root 4096 Mar 11 06:54 sampleDashboard [root@demoDB sampleDashboard]# ls -l total 8 -rw-r--r--. 1 root root 172 Mar 11 06:55 sample.wsgi drwxr-xr-x. 6 root root 4096 Mar 11 06:56 sampleDashboard [root@demoDB sampleDashboard]# ls -l total 16 drwxr-xr-x. 3 root root 4096 Mar 11 06:56 app -rw-r--r--. 1 root root 1074 Mar 11 06:56 run.py drwxr-xr-x. 2 root root 4096 Mar 11 06:56 static drwxr-xr-x. 2 root root 4096 Mar 11 06:56 templates
I guess am struck at the end, any help will be appreciated. Thanks
As the errors indicate, the configure
never ran properly so there was no point doing a make afterwards and trying to use the result.
I would need to see the result of running:
sh -x ./configure --with-python /opt/Anaconda/bin/python
to even start to work out what the problem is, but it looks a little like you may have some program in your PATH
which hides a normal system program, or there is something else incomplete about your operating system.
I really suggest you ignore the configure/make/make install
method and use the pip install
method I told you to use previously. That is run pip install mod_wsgi
to install it somewhere, and then run:
mod_wsgi-express module-config
to output the configuration to add to Apache to have it load the mod_wsgi version installed using pip
.
I ran the sh -x ./configure --with-python /opt/Anaconda/bin/python
command and https://gist.github.com/anubhaw2091/609c38bb94f6ced826759461f328e272 is the output of the command.
I totally agree that pip install mod_wsgi
is the easiest method for all this as this is what I did on my system and it works like a charm but I just can't access internet on company's server. That's out of question.
but it looks a little like you may have some program in your PATH which hides a normal system program, or there is something else incomplete about your operating system.
To replicate the scenario, I bought a OS from blue mix with minimal or literally nothing installed in it. Configuring mod_wsgi
is the first thing which am doing on this server.
[root@demoDB mod_wsgi-4.6.2]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.4 (Maipo)
I really don't have any option other than to install mod_wsgi offline on the company server and then run the dashboard which I made in flask.
Just hope I get a working solution.
Thanks
You can use pip install
offline. Instead of configure/make/make install
in the source directory, run:
pip install .
Whoa! That was damn simple. Thanks a ton @GrahamDumpleton
Note that if you have no network connectivity at all, you may have to supply the:
--disable-pip-version-check
option.
Another alternative is:
python setup.py install
You could also investigate building Python wheels on a separate box and then installing using pip
from a directory of pre-built wheel files for packages.
So lots of options for offline installs.
As to using configure, it seems it is important to use form:
./configure --with-python=/opt/Anaconda/bin/python
IOW, use =
on --with-python
and not have path to python
as separate argument.
Yeah. I did have to disable the version check in order to make it work. But I think, it's not mentioned explicitly anywhere as to how to install it offline(I might have missed it, no offence to you). It would be awesome if you could add something in installation guide explicitly for offline installation.
As to using configure, it seems it is important to use form:
./configure --with-python=/opt/Anaconda/bin/python IOW, use = on --with-python and not have path to python as separate argument.
I believe this is what was missing from my end. I didn't use "=" . I will try this on my company server and will give an update.
Gents I am having some troubles here.
I am trying to deploy a django project using an anaconda environment, with apache and mod_wsgi. I have managed to install mod_wsgi (using pip) and configure django (mod_wsgi-express). But I am not able to get it started. The critcal error message is:
OSError: /lib64/libz.so.1: version `ZLIB_1.2.9' not found (required by [path to my anaconda environments folder]/django37/lib/./libpng16.so.16)
I am able to start do the failing import when starting a django-shell, so I am wondering if I need to tell apache/mod_wsgi something special to get it to import the correct libraries (I can find the correct zlib files in my environ/lib folder).
Any help is appreciated.
@ellevset This is an old closed issue. Do not ask new questions on existing issues. Please create a new separate issue.
So I have been trying to install mod_wsgi on REDHAT7 from few days. Yet not succeed.
Following this link QUICK INSTALL.
So I have managed to install the file using
make install
.ldd /etc/httpd/modules/mod_wsgi.so
gives me the following.Inorder to get this, I had to set env variable.
I also added the following line in httpd file
LoadModule wsgi_module /etc/httpd/modules/mod_wsgi.so
But now when am trying to restart apache am getting error and when I run
journalctl -xe
I get the following.httpd: Syntax error on line 57 of /etc/httpd/conf/httpd.conf: Cannot load /etc/httpd/modules/mod_wsgi.so into server: libpython3.6m.so.1.0: cannot open sha....
My ultimate motive is to install a flask application on redHat.