Configure Apache for Python 3.4 on CentOS 6.5

To install the latest version of Python 3.4 on CentOS 6.5, you can use the previous article.

In order to work with python 3.4 the apache web server requires the wsgi module. If you have two pythons in your system (2.7 and 3.4) then this module needs to be built from sources. I assume that the site needs the latest version of Python to work.

Install the required packages:

yum install httpd-devel -y

Create the necessary symlinks:

ln -s /usr/local/lib/ /usr/lib64/
ln -s /usr/local/lib/ /usr/lib64/
cp /usr/local/lib/ /usr/lib/

Download, configure, install:

tar -xf mod_wsgi-3.4.tar.gz
cd mod_wsgi-3.4
./configure -with-python=/usr/local/bin/python3.4
make install

Everything is installed in a folder


It is left to enable the module.

echo 'LoadModule wsgi_module modules/' >> /etc/httpd/conf.d/wsgi.conf

create a config file for Django:

nano /etc/httpd/conf.d/django.conf

We bring it to the following form:

WSGIPythonPath /var/www/website

<VirtualHost *:80>

WSGIScriptAlias ​​/ /var/www/website/website/
<Directory /var/www/website/>
    Order deny, allow
    Allow from all

If you have several projects in different directories:

WSGIPythonPath /var/www/website:/var/www/website2:/var/www/website3

The file must be executable:

chmod +x /var/www/website/website/

You need to make sure that Apache is working:

apachectl -t

Restart it if all is well:

/etc/init.d/httpd restart

There might be problems related to selinux:

setenforce 0

Edit the file /etc/selinux/config and set: