sanPerl has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks
I am trying to learn CGI. I asked my sys-admin to install Apache on one Linux machine. Then I copied and pasted a simple CGI script, in a file (say x.cgi)
#!/usr/bin/perl -wT use strict; use CGI; my $query = CGI->new(); print $query->header( "text/html" ), $query->start_html(-title => "My First CGI Script", -bgcolor => "#ffffcc" ), $query->h1( "This is a pretty lame Web page" ), $query->p( "Who is this Ovid guy, anyway?" ), $query->end_html;
It simply prints code as it is on the browser. Do I need to change in Apache settings? Isn't there any simpler way to just get started, without touching Apache default settings?

Replies are listed 'Best First'.
Re: Basic CGI question
by wazoox (Prior) on Apr 05, 2006 at 10:55 UTC
    Yes, that means Apache doesn't identify your script as a special (executable) file. You should put the script in the cgi-bin directory (usually something like /var/www/cgi-bin), make it executable to everyone (well at least to the apache user of course), and check that your apache config 1) supports cgi 2) manage scripts with the .cgi extension. Something like :
    # you should have this one LoadModule cgi_module modules/mod_cgi.so # and this one ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" <Directory "/var/www/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory> # and this to manage the .cgi extension AddHandler cgi-script .cgi
Re: Basic CGI question
by marto (Cardinal) on Apr 05, 2006 at 11:06 UTC
    sanPerl,

    it looks like your working on Ovid's great Web Programming Using Perl tutorial. I suggest looking at Getting Your CGI Scripts Working, the section 'Is the server configured to execute the script, and are the permissions set' explains setting executable permissions, and what Apache configuration may not be in place, in which case you may need to contact your sysadmin to do this for you.

    Hope this helps.

    Martin
      wazoox and marto,
      Thanks a lot for your suggestions. It is working fine, now.
      Regards,
      Sandeep