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 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 install


Enable Apache module

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

LoadModule wsgi_module modules/


Restart apache

Quick Tip: Delete existing partitions during CentOS 7 installation

Got stuck recently during a remote gig installing CentOS. Vanilla install failed  due to a hardware error and had to be reinstalled but unlike the earlier versions there wasn’t a clearly defined path to delete existing partitions. So here is what we did;

Installation destination:

  1. Custom partitoning, create automatic partitions will prompt that there is not enough free space
  2. Click Done to go back
  3. Select Automatic partition, click Done
  4. Click the recover free space option on the Error prompt window
  5. Delete all exiting partitions (or as needed)
  6. Click preserve to save changes
  7. Click Done to go back
  8. The Disk free space displayed near the bottom has increased

That’s it. You can now proceed with the usual installation steps.

AMD Ryzen and CentOS 7 issues

Stability problem

Stock CentOS 7 has an old kernel 3.10.x which is causing major stability issues with AMD Ryzen 7 and the B350 series of motherboards.


Switch to the newer 4.1x kernel as follows;

Install latest 4.1x kernel from ElRepo

rpm --import
rpm -Uvh
yum --enablerepo=elrepo-kernel install -y kernel-ml

Reboot and select the 4.1x option in Grub boot options screen

Regenerate Grub2 config files

grub2-mkconfig -o /boot/grub2/grub.cfg

Change Grub settings

Edit /etc/default/grub
Change GRUB_DEFAULT = saved to 0


List Grub boot options

grep "^menuentry" /boot/grub2/grub.cfg | cut -d "'" -f2

Set default Kernel

grub2-set-default 0
grub2-editenv list

Reboot. Default boot will load the 4.1x kernel.


uname -r

Disable Kernel Updates

Update: yum installs or updates will revert back to the base kernel version 3.10.x, to stop kernel updates edit /etc/yum.conf and under the [main] section add line


or remember to add the exclude option during yum

yum -x 'kernel*' update