Search code examples
perlcgicgi-bin

Unable to get this simple Perl CGI program running


Can someone please explain to me the very basics of getting perl to work on a server. Do I need a module on the server? If so where does it go? What do I name my files and where do they go?

From my understanding you need a module and it goes in the cgi-bin. I can't get a clear answer whether I name the file .pl or .cgi and when I put it in the cgi-bin I am getting a server error. I also have my permissions set to 777, so that shouldn't be the problem.

Please help! I just want to understand the how to get the very basic program working such as the one below. Thanks in advance!

    #!/usr/bin/perl
    require("cgi-lib.pl");
    print &PrintHeader;

    print "<html>";
    print "<head><title>Hello world!</title></head>";
    print "<body>";
    print "<p>Hello world!</p>";
    print "</body>";
    print "</html>";

Solution

  • The latest version of cgi-lib.pl is dated 1999 and is very out of date. I suggest you use the CGI library instead, which is almost bound to be installed already on your server and is kept up to date (most recently on August 16 2012)

    Your program should look like this:

    #!/usr/bin/perl -- 
    
    use strict;
    use warnings;
    
    use CGI ':standard';
    
    print header;
    
    print <<END;
    <html>
      <head><title>Hello world!</title></head>
      <body>
        <p>Hello world!</p>
      </body>
    </html>
    END
    

    Also note that you can run the program from the command line to see if it compiles and what output it generates. Once you have it working there you can move it to the server