Monday, August 1, 2011

Ubuntu Desktop 11.04 - Apache CGI enable

Ubuntu Desktop 11.04 - Apache CGI enable

How to enable CGI in Ubuntu 11.04 with apache.
sudo vim /etc/apache2/conf.d/security
# Edit 27 line as below
ServerTokens Prod

# Edit 39th line as below
ServerSignature Off

$ sudo vim /etc/apache2/mods-enabled/dir.conf 
# Line 3 : Add directory index 
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

$ sudo vim /etc/apache2/mods-enabled/mime.conf 
# Line 218 : Add .cgi file as below.
AddHandler cgi-script .cgi .pl

$ sudo vim /etc/apache2/sites-available/default 
# Line 2: Add Administrator mail address
ServerAdmin webmaster@server.world

# Line 10: Add "ExecCGI" and Delete "Indexes"
Options FollowSymLinks ExecCGI

# Line 11: Allow none to all
AllowOverride All

$ sudo ln -s /usr/bin/perl /usr/local/bin/perl 
$ sudo /etc/init.d/apache2 restart
 
* Restarting web server apache2
... waiting . ...done.   [OK]

Now create the cgi file as below.
$ sudo vim /var/www/index.cgi

        #!/usr/local/bin/perl

        print "Content-type: text/html\n\n";
        print <<"EOM";
        <html>
        <body>
        <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
        CGI Test Page
        </div>
        </body>
        </html>
        EOM
        exit;

$ sudo chmod 705 /var/www/index.cgi

Access on the link below.
[http://localhost/index.cgi]