Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install mod_wgsi for apache 2.4+ with python3.5 on CentOS 7

As title says "How to install mod_wgsi for python3.5 on CentOS 7"?

$pip3.5 install mod_wgsi did not work

Collecting mod_wgsi
  Could not find a version that satisfies the requirement mod_wgsi (from versions: )
No matching distribution found for mod_wgsi

sudo yum install libapache2-mod-wsgi-py3 failed too:

Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager
This system is not registered with Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: mirror.daniel-jost.net
 * epel: mirrors.n-ix.net
 * extras: mirror.daniel-jost.net
 * ius: mirror.amsiohosting.net
 * remi: mirror.23media.de
 * remi-php56: mirror.23media.de
 * remi-safe: mirror.23media.de
 * updates: mirror.daniel-jost.net
No package libapache2-mod-wsgi-py3 available.
Error: Nothing to do

Any suggestions on how to run apache2.4+ mod_wsgi with python3.5 on CentOS 7 are very welcome!

like image 452
uzla Avatar asked Feb 02 '17 14:02

uzla


4 Answers

I tried following Carl's answer, but it didn't solve the problem. It turns out that the version I installed required some extra configuration steps after installation.

Background

I looked at Apache's modules folder before I installed the mod_wsgi upgrade:

$ ls -l /lib64/httpd/modules
[...]
-rwxr-xr-x. 1 root root 172800 Oct 30 22:44 mod_wsgi.so

Then I installed the SCL repository, and looked to see which versions of mod_wsgi are available.

$ sudo yum install -q -y centos-release-scl
[...]
$ yum search mod_wsgi
[...]
koschei-frontend.noarch : Web frontend for koschei using mod_wsgi
mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
python27-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
python33-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
rh-python34-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
rh-python35-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
rh-python36-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
viewvc-httpd-wsgi.noarch : ViewVC configuration for Apache/mod_wsgi
[...]

I'm using Python 3.6, so I installed the matching version and restarted Apache.

$ sudo yum install -q -y rh-python36-mod_wsgi
[...]
$ sudo systemctl restart httpd

Sadly, that didn't solve the problem. When I looked in Apache's modules folder, nothing had changed. Weird!

$ ls -l /lib64/httpd/modules
[...]
-rwxr-xr-x. 1 root root 172800 Oct 30 22:44 mod_wsgi.so

So what did get installed?

$ rpm -ql rh-python36-mod_wsgi
/opt/rh/httpd24/root/etc/httpd/conf.modules.d/10-rh-python36-wsgi.conf
/opt/rh/httpd24/root/usr/lib64/httpd/modules/mod_rh-python36-wsgi.so
/opt/rh/rh-python36/root/usr/share/doc/rh-python36-mod_wsgi-4.5.18
/opt/rh/rh-python36/root/usr/share/doc/rh-python36-mod_wsgi-4.5.18/CREDITS.rst
/opt/rh/rh-python36/root/usr/share/doc/rh-python36-mod_wsgi-4.5.18/LICENSE
/opt/rh/rh-python36/root/usr/share/doc/rh-python36-mod_wsgi-4.5.18/README.rst

Extra Configuration Steps

It installed the files I need, but it didn't put them anywhere useful. With some hints from the README.rst file, I copied them into the right place.

sudo cp /opt/rh/httpd24/root/usr/lib64/httpd/modules/mod_rh-python36-wsgi.so /lib64/httpd/modules
sudo cp /opt/rh/httpd24/root/etc/httpd/conf.modules.d/10-rh-python36-wsgi.conf /etc/httpd/conf.modules.d
sudo systemctl restart httpd

Now I have the right version of mod_wsgi, and my Django app will run under Apache.

like image 126
Don Kirkby Avatar answered Oct 23 '22 20:10

Don Kirkby


I see you already have the IUS repo enabled. Rather than jumping through SCL hoops, you can just install a normal package.

yum install python35u-mod_wsgi

This will use standard filesystem locations to work with stock Apache HTTPD 2.4.

/etc/httpd/conf.modules.d/10-wsgi-python3.5.conf
/usr/lib64/httpd/modules/mod_wsgi_python3.5.so
like image 20
carlwgeorge Avatar answered Oct 23 '22 21:10

carlwgeorge


Have you check the rh-python35 Software Collection which provides a rh-python35-mod_wsgi package ?

More information about SCL, see:

  • The Software Collection (SCL) Repository
  • The Software Collection Special Interest Group
  • RHSCL 2.3 release announcement
like image 1
Remi Collet Avatar answered Oct 23 '22 19:10

Remi Collet


I would use the SCL packages for python 3.6 (though feel free to substitute 3.5 below).

To start:

yum install centos-release-scl
yum install rh-python36 rh-python36-mod_wsgi

Note that will bring in the SCL package httpd24-httpd and put the mod_wsgi file in that installation. I would recommend you use that installation and not install the base CentOS httpd package. At time of writing, for CentOS 7, the httpd package is 2.4.6 and the httpd24-httpd package is 2.4.37.

Then you create a virtualenv with:

/opt/rh/rh-python36/root/usr/bin/python -m venv /path/to/venv36
source /path/to/venv36/bin/activate
pip install ...

Now you can put the config for your site in /opt/rh/httpd24/root/etc/httpd/conf.d/mysite.conf, which could contain something like:

<VirtualHost *:80>
    LoadModule wsgi_module modules/mod_wsgi.so

    ErrorLog /var/log/httpd24/mysite-err.log
    CustomLog  /var/log/httpd24/mysite.log combined

    # recommended way of setting DJANGO_SETTINGS_MODULE http://stackoverflow.com/a/25496668/3189
    WSGIProcessGroup mysite.settings.production
    WSGIDaemonProcess mysite.settings.production python-path=/path/to/mysite/:/path/to/venv36/lib/python3.6/site-packages
    WSGIScriptAlias / /path/to/mysite/wsgi.py process-group=mysite application-group=%{GLOBAL}
</VirtualHost>

Now you start the SCL apache with:

systemctl start httpd24-httpd

And your site should be working.

like image 1
Hamish Downer Avatar answered Oct 23 '22 19:10

Hamish Downer