Tuesday, October 25, 2011

Enabling and testing mod_wsgi with EasyApache for WHM/cPanel


This post explains how to enable mod_wsgi using easyapache script.

Step 1:
You have to download and extract custom_opt_mod-mod_wsgi.tar.gz. From the link given below.

Step 2:
After downloading it extract it to location identifiable by easyapache
tar -C /var/cpanel/easy/apache/custom_opt_mods -xzf custom_opt_mod-mod_wsgi.tar.gz

Step 3:
Now run /scripts/easyapache
select mod_wsgi option while configuring profile.

Thats it.

Testing mod_wsgi with apache on cpanel server. :

Step 1:
First you have to create a test file as follows
root@server [/usr/local/apache/htdocs/test]# cat index.wsgi
def application(environ, start_response):
    """Simplest possible application object"""
    output = "Hello World"
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]
root@server [/usr/local/apache/htdocs/test]#

Step 2:
And create one .htaccess file as follows.
root@server [/usr/local/apache/htdocs/test]# cat .htaccess
Options +ExecCGI
#DirectoryIndex DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm index.wsgi
AddHandler cgi-script .cgi
AddHandler wsgi-script .wsgi
<IfModule mod_wsgi.c>
WSGIScriptAlias /test /usr/local/apache/htdocs/test/index.wsgi
WSGIDaemonProcess root processes=5 threads=1 display-name=%{GROUP}
WSGIProcessGroup root
WSGIApplicationGroup %{GLOBAL}
root@server [/usr/local/apache/htdocs/test]#

And add following lines in httpd.conf and restart apache
root@server1 [/usr/local/apache/htdocs/test]# vi /usr/local/apache/conf/httpd.conf
<Directory "/usr/local/apache/htdocs/test">
Options +ExecCGI
AddHandler cgi-script .cgi

You can check the script using the following url

No comments:

Post a Comment

Be nice. That's all.