Python Web Programming Using Apache and mod-python

Python client/server programming with Apache and mod-python in Ubuntu 9.10.

1. Goto Synaptic Package Manager and install the following packages

a) apache2                                   [Apache Web Server]
b) libapache2-mod-python      [Module for running Python Programs in Apache using mod-python ]
c) mysql-server                          [Mysql Database Server]
d) mysql-client                         [Mysql Client Terminal]
e) pyhton-mysqldb                  [Pyhton and Mysql database programming fucntions ]
f)  python3,1                             [optional but i strongly suggesting you to learn python 3.x ]

2. After Installation You can start , stop, or restart the apache and mysql server using this commands

# sudo su
# /etc/init.d/apache2 start/stop/restart
# /etc/init.d/mysqld start/stop/restart

3. If You want to create mysql database , use the given command

# mysql -u root -p

[Type the password which  you had already given while installation of mysql server ]

4. Now Lets write one small web application  , Open Your favorite editor vim , gedit or Eclipse

# sudo su
# vim first.py
#!/usr/bin/python3.1
print(“Content-Type: text/html\n”)
print(“<b>My First Web Application in Python<b>”)

Save and copy the file into

# cp first.py   /usr/lib/cgi-bin
# chmod a+x /usr/bin/cgi-bin/first.py

5. Now Open your web browser and type the address like

http://localhost/cgi-bin/first.py

Thats it … Enjoy the power of Python programming …

2 Responses to “Python Web Programming Using Apache and mod-python”

  1. S.GaneshBabu says:

    Hello Antony

    I want to know how to configure Apache with mod python in windows environment.

Leave a Response