Python/Django app on CentOS 7 Apache server using mod_wsgi

Python/Django apps can be hosted on Linux Apache web server using the mod_wsgi module. However, the mod_wsgi module has to be compiled with  same version as the one in the virtual environment.

OS: CentOS 7.3

Python: 3.6.2

Get source code

Apache source

$ yum install httpd-deve

Download Python-3.6.2 Gzipped source tarball

Download mod_wsgi Source code (tar.gz)

 

Compile Python and mod_wsgi

Compile Python with the –enable-shared option

cd Puthon-3.6.*-source
./configure --enable-shared
make
make altinstall

 

Post compile add library path /usr/local/lib to ldconfig and check with

# ldconfig –v | grep python

 

now compile mod_wsgi

./configure --with-python=/usr/local/bin/python3.6
make
make install

 

Enable Apache module

Create /etc/httpd/conf.modules.d/10-mod_wsgi.conf

LoadModule wsgi_module modules/mod_wsgi.so

 

Restart apache