<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SenseHofstede.nl &#187; apache</title>
	<atom:link href="http://sensehofstede.nl/tag/apache/feed" rel="self" type="application/rss+xml" />
	<link>http://sensehofstede.nl</link>
	<description>Sense&#039;s blog</description>
	<lastBuildDate>Thu, 05 Aug 2010 17:32:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Get mod_python working</title>
		<link>http://sensehofstede.nl/get-mod_python-working</link>
		<comments>http://sensehofstede.nl/get-mod_python-working#comments</comments>
		<pubDate>Sun, 06 Apr 2008 13:54:32 +0000</pubDate>
		<dc:creator>Sense Hofstede</dc:creator>
				<category><![CDATA[Blog Posts]]></category>
		<category><![CDATA[English Posts]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.qense.nl/?p=78</guid>
		<description><![CDATA[With just installing the package libapache2-mod-python you&#8217;re not done yet. I tried to get it working but it turned out that I had to adapt the configuration files by myself. This is not how it should be in my eyes, &#8230; <a href="http://sensehofstede.nl/get-mod_python-working">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>With just installing the package libapache2-mod-python you&#8217;re not done yet. I tried to get it working but it turned out that I had to adapt the configuration files by myself. This is not how it should be in my eyes, since beginning Ubuntu users will have a hard time to get it working. Anyway, I&#8217;m going to file a bug after this post has been post.<br />
I based my guide on the official mod_python documentation, which can be found here: <a href="http://www.modpython.org/live/current/doc-html/">Mod_python Manual</a>.</p>
<p>The first step was to let apache send .py files to the python module to parse them. This is done by adding this following code to <em>/etc/apache2/sites-available/default</em>.</p>
<blockquote><p>AddHandler mod_python .py<br />
PythonHandler mod_python.publisher<br />
PythonDebug On</p></blockquote>
<p>Add this before &lt;/Directory&gt; in the &lt;Directory &gt;&lt;/Directory&gt; structure of the directory you want to enable python in. Make sure you restart apache now.</p>
<p>Now you want to execute some python code. This isn&#8217;t the same as with PHP. You can&#8217;t just write <em>print &#8220;Hello World&#8221;</em> and the browser will display Hello World. The handler works with different modules. You have to define in your file and request it with your URI. I&#8217;ll show you this with the example code from the documentation. Paste this in a file and save it as test.py:</p>
<pre>#!/usr/bin/python

""" Publisher example """
def say(req, what="NOTHING"):
return "I am saying %s" % what</pre>
<p>This code defines the module say. You can execute it by going to http://localhost/test.py/say if you&#8217;ve saved it in your server root. You probably already saw the variable what, which is passed on. This variable can be passed on in this way: http://localhost/test.py/say?what=hi<br />
The module name for the default one, if no module name is passed on is <em>index</em>. http://localhost/test.py will look for the module <em>index</em> and if that isn&#8217;t present it will return a 404 error. Please make sure you pass <em>req</em> on in every definition of a module. Note that if a non-existing module is requested a 404 error will be sent to the browser.</p>
<p>A note: Apache is restarted with <em>sudo apache2 -k restart</em>. If that doesn&#8217;t work for you, you can try it with <em>sudo dpkg-reconfigure apache2-mpm-prefork</em>.</p>
<p>If you find any errors in this blog post or think that certain things are incomplete or can be done better, please don&#8217;t hestitate to tell me. I&#8217;m not that experienced with python. <img src='http://sensehofstede.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://sensehofstede.nl/get-mod_python-working/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
