Pages

Sunday, September 25, 2016

Install apache2 and enable CGI for perl or python on Ubuntu

Install apache2 and enable CGI for perl or python on Ubuntu


To start with CGI-Programming, I assume you know basics of python and has basic knowledge of HTML.
I also assume, you have Ubuntu or any other Linux flavour to work on.

Let's get started then

  • First thing first, ensures you have apache installed on your Ubuntu distribution. If not install it using the CLI command: sudo apt-get install apache2
  • Edit the 000-default.conf file using the below command and enter the below few lines subsequently. Command to edit the file: sudo vim /etc/apache2/sites-available/000-default.conf . Now put these lines just below the line ServerAdmin webmaster@localhost
    DocumentRoot /var/www/
    <Directory /var/www/>
                  Options ExecCGI Indexes FollowSymLinks MultiViews
   AllowOverride None
  Order allow, deny
  allow from all
  AddHandler cgi-script .py
</Directory>
  • By Default on installation of apache2, the apache service starts running, just to be on safe side restart the service using the command: sudo service apache2 restart
  • Now the final setup for CGI enabling. Run this command and you are done.

            sudo a2enmod cgi
Now check if the apache for CGI-Programming got installed successfully and is ready to go by typing either localhost
OR
127.0.0.1 on any browser of your choice installed on your Ubuntu.

No comments:

Post a Comment