<?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>Prabeen&#039;s Blog &#187; CGI</title>
	<atom:link href="http://prabeengiri.com.np/category/cgi/feed" rel="self" type="application/rss+xml" />
	<link>http://prabeengiri.com.np</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 04 Jan 2011 18:31:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Start CGI Scripting using Python and Apache Server</title>
		<link>http://prabeengiri.com.np/python/cgi-scripting-using-python.html</link>
		<comments>http://prabeengiri.com.np/python/cgi-scripting-using-python.html#comments</comments>
		<pubDate>Mon, 26 Oct 2009 07:37:18 +0000</pubDate>
		<dc:creator>Prabeen</dc:creator>
				<category><![CDATA[CGI]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Apache Server]]></category>
		<category><![CDATA[Python for CGI]]></category>
		<category><![CDATA[start CGI scripting]]></category>

		<guid isPermaLink="false">http://prabeengiri.com.np/?p=118</guid>
		<description><![CDATA[Hello world CGI scripting using python  ,Apache Server , Common Gateway Interface, hello world  cgi scripting using python and apache server]]></description>
			<content:encoded><![CDATA[<p><strong> </strong>The<strong> Common Gateway Interface (CGI)</strong> is a standard protocol that defines how webserver software can delegate the generation of webpages to a console application.<br />
Such applications are known as CGI scripts &#8211; they are usually written in a scripting language.</p>
<p><strong>Python</strong> is a free interpreted and object oriented programming that allows you to create any type of applications compatible with all common operating systems.<br />
You can deploy stand-alone applications or CGI scripts. There are many web servers that provide support for deploying <strong>Python</strong> scripts.<span id="more-118"></span></p>
<p>If you are using an <strong>Apache web server</strong> on Windows platform, you have many alternatives to set up a certain configuration that will allow you to run Python scripts through CGI. The configuration of <strong>Apache web server</strong> can be performed by editing the httpd.conf file.</p>
<p>First you will need to download and install the latest <strong>Python</strong> for Windows distribution package. It is recommended to install it directly on the root of the c: drive with the executable file (python.exe) situated in c:\Python directory. The file httpd.conf is located in the apache installation directory in a folder called conf.</p>
<p>This file contains the usual <strong>Apache</strong> configuration directives that can be enabled by uncommenting a certain line. In case of <strong>Python CGI</strong> scripts, the line containing the AddHandler directive from the http.conf file must have the next structure:</p>
<p><span id="intelliTxt"> </span></p>

<div class="wp_syntax"><div class="code"><pre class="command" style="font-family:monospace;">AddHandler cgi-script .cgi .py .pl</pre></div></div>

<p><span id="intelliTxt">In this way, Apache web server will treat Python and Perl files as CGI scripts. The second modification that must be made to Apache configuration file is the specification of the location of your cgi-bin directory by adding the full path to it in the next line (you must replace C:/apache/cgi-bin with the path of your cgi-bin directory):</span></p>
<p><span id="intelliTxt"> </span></p>

<div class="wp_syntax"><div class="code"><pre class="command" style="font-family:monospace;">ScriptAlias /cgi-bin/ &quot;c:/apache/cgi-bin/&quot;</pre></div></div>

<p><span id="intelliTxt">After you save the http.conf file and restart the Apache web server, you will have support to run Python scripts. You can test if the server configuration was successful with the next example (copy and paste the code in a text file and save it as test.py):</span></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!C:/Python31/python.exe</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">cgi</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">cgitb</span>
<span style="color: #dc143c;">cgitb</span>.<span style="color: black;">enable</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># for troubleshooting</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#print header</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Content-type: text/html&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;&lt;!DOCTYPE html PUBLIC <span style="color: #000099; font-weight: bold;">\&quot;</span>-//W3C//DTD XHTML 1.0 Strict//EN<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\&quot;</span>http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;&lt;html&gt;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;&lt;head&gt;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;&lt;title&gt;Python CGI Hello World&lt;/title&gt;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;&lt;/head&gt;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;&lt;body&gt;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;&lt;p&gt;Hello, world!&lt;/p&gt;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;&lt;/body&gt;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;&lt;/html&gt;&quot;</span></pre></div></div>

<p><span id="intelliTxt">The file <strong>test.py</strong> must be copied in your cgi-bin directory. Then type into your web browser address bar:</span></p>
<p><span id="intelliTxt"> </span></p>

<div class="wp_syntax"><div class="code"><pre class="command" style="font-family:monospace;">http://localhost/cgi-bin/test.py</pre></div></div>

<p><span>Now we can see browser printing &#8216;Hello World&#8217;..</span></p>
<p><span>Reference :  <a href="http://news.softpedia.com/news/Your-First-Python-Script-on-Windows-81974.shtml" target="_blank">Softpedia</a> , <a href="http://en.wikipedia.org/wiki/Common_Gateway_Interface">Wikipedia</a><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://prabeengiri.com.np/python/cgi-scripting-using-python.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

