On Java, Python, Groovy, Grails, Spring, Node.js, Linux, Arduino, ARM, Embedded Devices & Web

  • Recent Posts

    December 2011
    M T W T F S S
    « Oct   Feb »
  • Subscribe Options

  • Awards

  • Most Valuable Blogger @ DZone
  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 175 other followers

  • Follow MyThinkPond on
  • Blog Stats

    • 366,804 hits
  • General Options

How-To Install mod_python and the compile error – apxs:Error: Command failed with rc=65536

Posted by Venkatt Guhesan on December 28, 2011

Below are my steps to installing mod_python under Apache HTTPD in CentOS 6.2.

Download mod_python-3.3.1.tgz or a later version of mod_python available here:

curl -O
tar zxvf mod_python-3.3.1.tgz
cd mod_python-3.3.1

You may encounter the following error at this point:
apxs:Error: Command failed with rc=65536

If so… no worries…

This bug has been addressed here:

Download the patch and (if you can figure out how to patch like I did, I manually opened the file and examined the contents:

diff -rNu mod_python-3.3.1/src/connobject.c mod_python-3.3.1-atomix/src/connobject.c
--- mod_python-3.3.1/src/connobject.c 2006-12-03 05:36:37.000000000 +0100
+++ mod_python-3.3.1-atomix/src/connobject.c 2008-10-02 14:10:02.000000000 +0200
@@ -139,7 +139,7 @@
bytes_read = 0;

while ((bytes_read < len || len == 0) &&
+ !(b == APR_BRIGADE_SENTINEL(bb) ||

const char *data;

Based on the file contents… Edit the following file below the unzipped folder (/mod_python-3.3.1/src/connobject.c)

Change line 142 from

Save the file. And then run “make” again.

This time you should see no errors. The last step is to run “make install” and you’re all set.

Now don’t forget to edit your main config and add
LoadModule python_module /usr/lib64/httpd/modules/
and if your configuration uses ClearModuleList, then also
AddModule mod_python.c

Next, Configure mod_python to work with Apache

Edit your httpd.conf (/etc/httpd/conf/httpd.conf), add:

LoadModule python_module /usr/lib64/httpd/modules/

#Under the AddHandler section

<Directory /var/www/html>
    AddHandler mod_python .py
    PythonHandler myscript
    PythonDebug On

To learn what the “AddHandler” does go here:

Stop and Start Apache HTTPD (/etc/init.d/httpd restart)

You’re all set.

To verify, create a file in your DocumentRoot (/var/www/html)


from mod_python import apache

def handler(req):

    req.content_type = "text/plain"
    req.write("Hello World from Apache HTTPD!")

    return apache.OK

As a last step, goto http://<your_ip&gt;:<your_port_80>/

You should see, “Hello World from Apache HTTPD!”. Notice that I didn’t goto “”. And I have pointed to “myscript” in the AddHandler parameter. This “” acts like the Controller in a MVC framework. So if you were installing an application like Django… then Django will act as the gatekeeper passing requests back and forth.

To learn more about the handler, go here:

or here’s an excerpt from that site:

Note that according to the configuration written above, you can also point your browser to any URL ending in .py in the test directory. You can for example point your browser to /test/ and it will be handled by That’s because you explicitely set the handler to always be mptest, whatever the requested file was. If you want to have many handler files named, and so on, and have them accessible on /test/, /test/, etc., then you have to use a higher level handler system such as the mod_python publisher (see 3.1), mpservlets or Vampire. Those are just special mod_python handler that know how to map requests to a dynamically loaded handler.

After writing this blog, I noticed that some users may prefer a PHP like feel. This can be done by adding a “Publisher Handler” (PSP).

Edit your httpd.conf (/etc/httpd/conf/httpd.conf), add:

LoadModule python_module /usr/lib64/httpd/modules/

#Change AddHandler to the following

<Directory /var/www/html>
   AddHandler mod_python .psp .psp_
   PythonHandler mod_python.psp
   PythonDebug On

Stop and start httpd (/etc/init.d/httpd restart).

Now create a file “test.psp” under DocumentRoot (/var/www/html)

import time
weekday = time.strftime('%A', time.localtime(time.time()))
message = 'Today is %s.' % weekday
<h2><%= message %></h2>

When you visit http://<your_ip&gt;:<your_port_80>/test.psp

You should see “Today is —” message.

You can learn more about the PSP handler here:



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: