Thursday, August 2, 2012

Setting up a webserver with python server side

Time to install the lamp stack and mod_python on my Ubuntu 10.04 box...
Great news... its really easy. Just run...

sudo apt-get install tasksel
sudo tasksel install lamp-server


This installs apache2, mysql and php. It will ask you for the mysql root/admin password during the installation. So give it a password of your choice... this need not be your login password, but it can be same. Make it different to increase security.

Detailed instructions for setting up Apache, PHP and MySQL individually are given here... https://help.ubuntu.com/community/ApacheMySQLPHP


Once that is done, we now install mod_python into the apache2 web server and restart the server...

sudo apt-get install libapache2-mod-python
sudo service apache2 restart


Now, to create our own site by replacing the default site, we need to edit the apache2 configuration. (instructions from the above linked site)

To create a new site:
  1. Copy the default website as a starting point.
    • sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite 
  2. Edit the new configuration file in a text editor "sudo nano" on the command line or "gksudo gedit", for example: 
    • sudo gedit /etc/apache2/sites-available/mysite
  3. Change the DocumentRoot to point to the new location. For example, /home/user/public_html/
  4. Change the Directory directive, replace <Directory /var/www/> to <Directory /home/user/public_html/>
  5. Add python scripting support...
    •     <Directory /home/user/public_html/>
              Options Indexes FollowSymLinks MultiViews
              AllowOverride None
              Order allow,deny
              allow from all
              AddHandler mod_python .py
              PythonHandler mod_python.publisher
              PythonDebug On
          </Directory>
  6. You can also set separate logs for each site. To do this, change the ErrorLog and CustomLog directives. This is optional, but handy if you have many sites
  7. Save the file
  8. Restart apache
    • sudo service apache2 restart 
  9. Add a test python script into your new website
    • gedit /home/user/public_html/test.py



No comments:

Post a Comment