Mod wsgi

From Wiki
Jump to: navigation, search

Intro

The aim of mod_wsgi is to implement a simple to use Apache module which can host any Python application which supports the Python WSGI interface. The module would be suitable for use in hosting high performance production web sites, as well as your average self managed personal sites running on web hosting services.

http://www.wsgi.org/

There are numerous web application frameworks supporting WSGI:

CherryPy, Django, web.py, web2py, TurboGears, Tornado, Pylons, BlueBream, nginx, Trac, Flask, Pyramid, Bottle, weblayer

This installation guide will aim to install from within cpanel so future easyapaches will not nuke it.

Installation

Install a updated Python

This will install a new version but will leave the default python version in place.

cd /usr/local/src/
wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
tar zxvf Python-2.7.2.tgz
cd Python-2.7.2
./configure --enable-shared
LD_RUN_PATH=/usr/local/lib make
make install

The following should run without error and show the version as 2.7. CTRL - D to exit.

/usr/local/bin/python2.7 

The following should still show 2.4.

python

Mod WSGI Installation

Warning: This module no longer works with Apache 2.4 or the latest cPanel release (11.50)

Get the custom EA script and mod wsgi

cd /usr/local/src
wget -O - http://watters.ws/rpms/cpanel/custom_opt_mod-mod_wsgi-4.4.13.tar.gz | tar -C /var/cpanel/easy/apache/custom_opt_mods -xzf - 

Run /scripts/easyapache. Select mod_wsgi from the Short options list. Save and build.

Testing

Add the following to a .htaccess file in the directory you want to test from (/home/<user>/public_html/test).

Options +ExecCGI
AddHandler wsgi-script .wsgi

Create test.wsgi file to verify that mod_wsgi is working.

su - <user>
cd ~/public_html/test - mkdir if not there
wget http://watters.ws/scripts/test.wsgi

You should now be able to run the script by doing to /test/test.wsgi on the user's domain.

Manual Installation

cd /usr/local/src
wget -O mod_wsgi-4.4.13.tar.gz 'https://github.com/GrahamDumpleton/mod_wsgi/archive/4.4.13.tar.gz'
tar xzvf mod_wsgi-4.4.13.tar.gz 
cd mod_wsgi-4.4.13
./configure --with-apxs=/usr/local/apache/bin/apxs
make && make install

Add the module to the pre_virtual_global.conf file.

LoadModule wsgi_module /usr/local/apache/modules/mod_wsgi.so

Restart httpd.

Check if the module is loading using httpd -G or httpd -M.

Done.

To compile wsgi with a custom python version (like 2.7 in this case), use this as your configure command:

./configure --with-python=/usr/local/bin/python2.7 --with-apxs=/usr/local/apache/bin/apxs