Archive for category Python Core
Install Python on Linux Ubuntu
Posted by admin in Python Core on September 6, 2008
In this article, I will explain how to install and run Python as a web service anywhere on Linux Ubuntu as localhost.
1. you should have have the latest version of Python installed, to do so, type the following line of code in the terminal:
sudo apt-get install python
2. Now to run it as a web service with Apache, you need Apache mod_python, to install it, type the following line of command in the terminal:
sudo apt-get install libapache2-mod-python
3. Now if you use the default localhost directory – /var/www/, then following the instruction a, if you have previously configured Apache and run localhost at the place other than the default /var/www/, follow the instruction b:
a.
execute the following command in the terminal:
cd /etc/apache2/sites-available/
and execute the following command:
sudo gedit default
now with the file opened, find the code below:
Options Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2′s
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
change it to:
Options Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
# Uncomment this directive is you want to see apache2′s
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
run in terminal:
sudo gedit /var/www/test.py
in the opened file, type:
def index(req): return "Test successful";
save the file, and it should work
visit http://localhost/test.py and it should say “Test successful” in plain text
b.
execute the following command in the terminal:
sudo gedit /etc/apache2/apache2.conf
assume that you are running Python code from the directory /home/usr/Documents/Host/lab/python/
add the following code to the bottom of the file:
Alias /python/ /home/usr/Documents/Host/lab/python/
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
run in terminal:
sudo gedit /home/usr/Documents/Host/lab/python/test.py
in the opened file, type:
def index(req): return "Test successful";
save the file, and it should work
visit http://localhost/test.py and it should say “Test successful” in plain text










































