1. Install apache2 first, after the installation you should be able to see the default page with 'localhost' in your browser.
Code: Select all
sudo apt-get install apache2
Code: Select all
sudo a2enmod cgid
cd /etc/apache2/mods-enabled
sudo ln -s /etc/apache2/mods-available/cgi.load
Code: Select all
<Directory "usr/lib/cgi-bin">
... ...
AddHandler cgi-script .py # add this line (there is a blank between cgi-script and .py)
</Directory>
Code: Select all
sudo nano /usr/lib/cgi-bin/pytest.py
Code: Select all
#!/usr/bin/python
import cgi
import cgitb
cgitb.enable()
print 'Content-type: text/html\n\n'
print '<h1>Python Script Test</h1>'
Code: Select all
sudo chmod +x /usr/lib/cgi-bin/pytest.py
Code: Select all
sudo service apache2 restart
Note: I was having trouble restart the apache2 service after enable the cgi mods. So I actually reinstalled the apache2, it works after that. Here is how I reinstalled the apache2:
Code: Select all
sudo apt-get --purge remove apache2
sudo apt-get autoremove
sudo apt-get install apache2