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/libpython3.so /usr/lib64/libpython3.4.so
ln -s /usr/local/lib/libpython3.4m.so.1.0 /usr/lib64/libpython3.4m.so.1.0
cp /usr/local/lib/libpython3.4m.so /usr/lib/

Download, configure, install:

wget https://modwsgi.googlecode.com/files/mod_wsgi-3.4.tar.gz
tar -xf mod_wsgi-3.4.tar.gz
cd mod_wsgi-3.4
./configure -with-python=/usr/local/bin/python3.4
make
make install

Everything is installed in a folder

/usr/lib64/httpd/modules

It is left to enable the module.

echo 'LoadModule wsgi_module modules/mod_wsgi.so' >> /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>
ServerName website.com

WSGIScriptAlias ​​/ /var/www/website/website/wsgi.py
<Directory /var/www/website/>
  <Files wsgi.py>
    Order deny, allow
    Allow from all
  </Files>
</Directory>
</VirtualHost>

If you have several projects in different directories:

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

The wsgi.py file must be executable:

chmod +x /var/www/website/website/wsgi.py

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:

SELINUX=disabled

Tags:

Categories:

Updated: