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

I tried to open a Perl script I had written with Netscape in Linux, however, instead of running the script, Netscape just displayed the script's code. What could be the problem?

Thanks in advance.

-- Zenon Zabinski

Replies are listed 'Best First'.
Re: Linux - Perl problem
by chromatic (Archbishop) on Jun 23, 2000 at 21:45 UTC
    You don't have a web server installed, or, you don't have the server configured to execute Perl programs.

    As far as Netscape knows, a Perl program is just a text file, so it treats it as a text file. It's the web server that actually executes it, returning HTML, text, an image, or some other kind of file to the web browser.

Re: Linux - Perl problem
by swiftone (Curate) on Jun 23, 2000 at 22:15 UTC
    1. Did you access it via a webserver? Did your location say "http://127.0.0.1/myscript.pl" or "/usr/local/httpd/myscript.pl"? The latter form will access it via the file system and not run the script.
    2. If you accessed it via a webserver, does the webserver know what to do with it? In apache, this means that your httpd.conf needs to have a Script-handler set (If you are using a script directory, such as /cgi-bin/), and the directory the file is in needs to have ExecCGI set. See the Apache docs. (The httpd.conf file should have lots of example text in it if it is a recent version.) httpd.conf will usually be located in one of:
      • /etc/httpd.conf
      • /etc/httpd/httpd.conf
      • /home/httpd/conf/httpd.conf (Why RedHat insists on using "/home" I'll never know)
      • /usr/local/httpd/etc/httpd.conf
      • /usr/local/httpd/conf/httpd.conf
      • /usr/local/apache/conf/httpd.conf
      • /usr/local/apache/etc/httpd.conf
      I'm sorry if I am annoying you, but I am new at this.

      I installed Apache and I am now able to access the files using the 'http://abc/abc' format. However, whenever I tried to run the Perl script, I get asked if I want to "save it as".

      So, I went and tried to edit 'httpd.conf'. I put the following lines in hoping that it would allow me to run the scripts:

      <Directory /myfolder> Options ExecCGI </Directory>

      But that didn't work. I even put in the following instead:

      <Directory /myfolder> AllowOverride None Options +ExecCGI -Include SetHandler cgi-script .cgi <IfDefine PERL> AddHandler perl-script .pl </IfDefine> </Directory>

      ...or something like that(I'm writing off the top of my head). Failure once again. Can you please help me out?

      -- zdog (Zenon Zabinski)
         Go Bells!! '¿'

      Update: I finally got it after hacking into 'httpd.conf' for three hours. Thank you for everybody's help.

        Be sure that you're returning a valid header to the browser before any content. The standard header for HTML is: Content-type: text/html, followed by two newlines. If you're using CGI.pm, you can use the following: print $q->header(); Since you're privileged enough to use a Unix-like system, the Idiot's Guide to Solving Perl CGI Problems may be of use to you. (I read it five or six times while making my first Perl CGI, and two times for the second. Don't mind the title.)
        I know this is Perl Monks, not Apache Monks :^P but am curious what resolution you found, zdog. I might be of some assistance in further tweaking your Apache configs.
            cheers,
            ybiC
      RedHat 6.0 and 6.1 put the config in /etc/httpd/conf/* and just the html and scripts in /home/httpd
      I don't know anything about other versions, though.
      Paris Sinclair    |    4a75737420416e6f74686572
      pariss@efn.org    |    205065726c204861636b6572
      I wear my Geek Code on my finger.