How do I compile mod_wgsi for Python 2.7

Recently I found myself in a situation where I needed to recompile mod_wgsi against a newer version of Python.

This involves recompiling Python with the correct flags, then recompiling mod_wsgi using the newly compiled Python. Below shows the steps,

Check Version

First of all check what version of Python mod_wsgi was compiled with.

[root@server]# ldd /usr/lib64/httpd/modules/ => /usr/lib64/ (0x00002b3149c4e000) => /lib64/ (0x00002b3149f82000) => /lib64/ (0x00002b314a19d000) => /lib64/ (0x00002b314a3a2000) => /lib64/ (0x00002b314a5a5000) => /lib64/ (0x00002b314a828000)
/lib64/ (0x000000364b200000)


Compile Python

Next, compile Python. The option to build a shared library is also used to prevent future issues (details can be found here).

yum groupinstall “Development tools”
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel

cd ~
tar xvf Python-2.7.5.tgz
cd Python-2.7.5

./configure –enable-shared –with-threads
make install

Once you have complete these steps you may get the error,

/usr/local/bin/python2.7: error while loading shared libraries: cannot open shared object file: No such file or directory

There are 2 ways to fix this. You can :

1. run ‘echo export LD_LIBRARY_PATH=/usr/local/lib >> /etc/profile’ or

2. configure the following softlinks

ln -s /usr/local/lib/ /usr/lib/
ln -s /usr/local/lib/ /usr/


Compile WSGI

Finally we compile wsgi,

cd ~
tar xvf mod_wsgi-3.4.tar.gz
cd mod_wsgi-3.4

./configure  –with-python=/usr/local/bin/python2.7
make install



Rick Donato

Want to become a programming expert?

Here is our hand-picked selection of the best courses you can find online:
Python Zero to Hero course
Python Pro Bootcamp
Bash Scripting and Shell Programming course
Automate with Shell Scripting course
The Complete Web Development Bootcamp course
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial