Saturday, June 4, 2011

web.py, mod_wsgi , RHEL6

web.py can be run in a production environment on RHEL6 with mod_wsgi using stock packages from yum with the exception of web.py itself (which can be inserted into the system Python library).

1. Install the packages that RHEL6 provides:

 yum install httpd mod_ssl mod_wsgi mysql-devel MySQL-python 

2. Insert web.py directly into RHEL's python2.6 site-packages:

cd /tmp
wget http://pypi.python.org/packages/source/w/web.py/web.py-0.35.tar.gz
tar xzf web.py-0.35.tar.gz
cd /usr/lib/python2.6/site-packages
mv /tmp/web.py-0.35/web .

3. Configure a place to host your application:

mkdir /var/www/myapp

4. Install some basic code in /var/www/myapp/code.py

import web
urls = (
        '/.*', 'hello',
        )
class hello:
        def GET(self):
                return "Hello World"
application = web.application(urls, globals()).wsgifunc()

5. Configure mod_wsgi directives for Apache in /etc/httpd/conf.d/wsgi.conf:

LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /myapp /var/www/myapp/code.py/
<Directory /var/www/tentacle/>
  Order allow,deny
  Allow from all
</Directory>

When configuring the above I used the webpy.org cookbook as a reference. Note that my previous example was development only.

No comments: