Firefox 16, a treat for developers http://t.co/cnd27CzT
How to set up Python scripting for Apache
In this post i will show you how to set up Python scripting for Apache. Note that I assume that you have already set up and configured the standard LAMP server stack. If you haven’t, refer to any of the following links, depending on your distribution. (Open Suse,Mandriva,Arch Linux, Debian,Sientific Linux)
If you have some experience with python and want to create dynamic websites with it, then look further.
Dynamic websites doesn`t serve html files stored on the server, the content is, instead, dynamically generated by a program running on the server. That is where python, php, perl, ruby etc. comes in.
As most servers are not written in those languages, an interface is needed for the server and the interpreter to communicate. The Common Gateway Interface is one such interface, which is widely supported. Another option is to install Apache’s mod_python, which puts a python interpreter within the server itself, thus removing the overhead of the interpreters startup time for each request, in lieu of using more memory.
Setting up cgi is quite simple as Apache generally installs mod_cgi by default.
1.Create a folder called “cgi-bin” in the DocumentRoot folder of the server (typically in “/var/www” or “/srv/http”).
2. In that folder, put a script or program, with executable permission set.
For more information on cgi programming and troubleshooting, look here: http://httpd.apache.org/docs/2.0/howto/cgi.html
Here is a simplistic “Hello world” program written in python:
[code]
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
print ("Content-Type: text/plain;charset=utf-8n")
print ("Hello World!")
[/code]
Mod python, on the other hand, is touted as faster and more flexible than using the cgi.
To install mod_python in Ubuntu, install the packages “libapache2-mod-python” and “python-mysqldb”, the last one is for handling databases.
The package “mod_python” is to be installed for Fedora. It is also available in the AUR for Arch Linux.
Next, you have to set up a handler so that the server process knows how to handle python programs. The two commonly used ones are the Publisher handler and Python Server Pages, the former catering to standalone python scripts and the later allowing embedded python code within html documents.
With the default virtual hosting setting in Ubuntu, you have to add the following code in the configuration file located in “/etc/apache2/sites-available/default”
<Directory /var/www/>
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
</Directory>
for the publisher handler. The equivalent for the psp handler is mod_python.psp as a handler for .psp .
Quick introductions, on how to use them, can be found
http://www.modpython.org/live/current/doc-html/tut-pub.html
and
http://www.modpython.org/live/current/doc-html/hand-psp.html#hand-psp
respectively.
Once you are familiar with the above it is a good idea to install a Web framework like Django, which abstracts away many of the boilerplate tasks needed for a good Web Application.
Like us on Facebook
This week Top Posts 
Top Things to do After Installing Ubuntu 13.04 ‘Raring Ringtail’ : Ubuntu 13.04 Raring Ringtail final is almost out. The final release it scheduled for release on Apri...0 comment(s) |
Install lamp with 1 command in Ubuntu 12.10, 13.04 Raring Ringtail & LinuxMint13 : Updated: 10/09/2012 :LAMP (Linux, Apache, MySQL and PHP) is an open source Web development platform ...0 comment(s) |
Howto: Upgrade to Ubuntu 13.04 Raring Ringtail from 12.04, 12,10 | Desktop & Server : Updated 05-04-2013: Ubuntu 13.04 Raring Ringtail will be released Soon, If you have ubuntu 12,10, 12...0 comment(s) |
Steganography- Hide Your Files Inside An Image in Linux : Nowadays, our personal computer is not only a work tool, it is also our private space where we sto...1 comment(s) |
How to use Remote Desktop in Ubuntu : Sometimes, we need to access our computer from other locations when we’re not at home and such. This...0 comment(s) |
Configure conky-Lua in Ubuntu (12.10 & 13.04 Raring Ringtail), Fedora, debian and LinuxMint | Howto Conky : Updated 05-04-2013: Conky is a free, light-weight system monitor for X, that displays any informatio...0 comment(s) |
Recent Posts
- Steganography- Hide Your Files Inside An Image in Linux
- Unix/Linux File Recognition. Did You Know?
- Migrate from MySQL to MariaDB in FreeBSD
- Connect Your Android Galaxy Tablet to Ubuntu via USB
- ElementaryOS Beta 1 and 2 Comparison and Review
- Introduction to the Linux Command Line
- A Secure Password
- Linux Kernel 3.10. It’s BIG!
- Monitoring Users Activity Using psacct or acct Tools in Linux
- Run Your Own Social Network Using elgg on RHEL / CentOS and Scientific Linux
Recent Comments



















SK
| #
Hey Abhishek
Yes there are many open source tools available to meet your requirements. They are easy to manage and has a decent web gui to configure. We will publish all of them one by one shortly. Stay tuned with us.
LinuxSytesNet
| #
sabayon facebook group is not maintained by him but a French guy. Go back to your zorin os.
Nidal Samara
| #
How do I save the entier URL?
for example: page.asp?page=12,
After adding the IfModule in .htaccess I see the correct 404, but 404 url is not shoing the query string , only page.asp
abhishek Bagusetty
| #
Hey Mel,
First of all, its good that you have figured a way to block torrents using iptables. I am new to networking and would like to do couple of things.
1) Monitor the network activity in the home network
2) Block all the torrents from downloading.
Is there a tool or a way in linux which could give me some solutions to meet the above mentioned cases. I dont want to use any commercial programs as I am more towards OpenSource. It would be greatful if you could offer me some help.
Thanks,
Abhi
Abhishek
Department of Chemical Engineering
The University of Utah
Ernesto Gutierrez
| #
Mel, I’ve been unsuccessful at installing citrix receiver on a 64 bit fedora install.
Eventhough I am following your instructions to the T.
Can you provide guidance via email?