Chriskuei Keep calm and code on

CentOS+Apache+Flask

Install WSGI

Download from GitHub, compile from source:

$ ./configure --with-python=*your_python_path*
$ make
$ make install

Or install by pip

$ pip install mod_wsgi

You can find package path by python -m site , then copy mod_wsgi to Apache’s modules directory

$ cp mod_wsgi.so /etc/httpd/modules/mod_wsgi.so

Configure Apache

Open configure file

$ vim /etc/httpd/conf/httpd.conf

In configure file, add code:

WSGIScriptAlias /url /var/www/html/flask/flask.wsgi
WSGIScriptReloading On
<Directory "/var/www/html/flask">
	AllowOverride All
	Require all granted
</Directory>

Configure WSGI

The directory structure is

flask/
├──app
|  ├── __init__.py
|  └── other.file
└── flask.wsgi

Edit flask.wsgi

import sys
import os

sys.path.insert(0, "/var/www/html/flask")
from app import app
application = app

Congratulation! All have done

Questions

libpython3.6m.so.1.0

Apache log is store in /etc/httpd/logs/error.log. If this error occurs

python3: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory

Find libpython3.6m.so.1.0 path

$ find / -name 'libpython3.6m.so.1.0'

Create python3.conf In directory /etc/ld.so.conf.d. Edit python3.conf

/usr/local/lib/ # This directory is where libpython3.6m.so.1.0 in

Then run

$ ldconfig

Fix “FAILED TO MAP SEGMENT FROM SHARED OBJECT: PERMISSION DENIED”

We can temporarily turn off SElinux by making it in permissive mode

$ getenforce
Enforcing
$ sudo setenforce 0
$ getenforce
Permissive

If you want to permanently solve the problem, need to edit the selinux config file

$ sudo vim /etc/selinux/config

Change SELINUX=enforcing to SELINUX=disabled.