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

Hi All, I have written a cgi script to display an image in the browser. I want to use it only locally on my computer (so it is not a public website). When I was opening this script from the browser, I see the code rather than the output of the code. I was suggested to install a webserver and configure the httpd.conf file to do this job. So, I have installed Apache in my home directory and modified the httpd.conf file to include the following (as per the suggestion given in this forum)
<Directory "/home/nagesh/apache/cgi-bin"> AllowOverride None Options ExecCGI Order allow,deny Allow from all </Directory>
After doing this, I again tried to open the cgi script (located in /home/nagesh/apache/cgi-bin) from the browser after running chmod 755 on it. This is still displaying the code rather than executing it. Can some please let me know is there any other changes I need to include in httpd.conf file to do this job. Any help would be greatly appreciated (Please note that I have no experience in webservers). Thanks very much for your attention.
Nagesh

20050727 Edit by ysth: code, br tags

Replies are listed 'Best First'.
Re: Setting up Apache to execute .cgi file
by ikegami (Patriarch) on Jul 28, 2005 at 02:31 UTC

    This is a Perl forum, and you question is not a Perl question. The appropriate place to ask Apache questions in on the Apache support mailing list.


    Did you tell Apache that .cgi files are CGI programs? Add

    AddHandler cgi-script cgi pl

    to your <Directory>.

      Don't forget the
      ScriptAlias /cgi-bin/ /home/george/Apache/cgi-bin/
      directive.

      Also you might have a look at http://www.thesitewizard.com/archive/addcgitoapache.shtml which has a tutorial on how to set up CGI scripts on Apache for Win32.. now I know you're not using Win32 but have a read through there anyway for the general CGI configuration steps. (At least you chmod'd your script, that's a good start).

        ScriptAlias was included by default. Still in the same situation. Thanks for the link Nagesh
      Hi There, Thanks for the response. I added the line you suggested but there is no change as it still displays the code <Directory "/home/nagesh/apache/cgi-bin"> AllowOverride None Options ExecCGI Order allow,deny Allow from all AddHandler cgi-script cgi pl </Directory> Do I have to change any permission for the script I am trying to run? Thanks Nagesh
        Did you restart the Apache server? Apache needs a restart to re-read the config file.

        Cheers,

        Brent

        -- Yeah, I'm a Delt.
Re: Setting up Apache to execute .cgi file
by cfreak (Chaplain) on Jul 28, 2005 at 04:05 UTC

    Are you accessing the script through the webserver eg: ( http://localhost/~yourhome/cgi-bin/script.cgi)? The webserver isn't doing anything if you're just opening the file in the browser directly.

    Also the httpd.conf information I gave you in the other thread was an example. I apologize for not being clearer but you'll need to read the docs so you'll know how all the configuration values you need for your specific setup. For instance if you're installing Apache in your home directory you'll likely not have permission to run it on the default port and you'll have to use a different one.

    And FYI, in the future you should add to the existing thread instead of starting a new one

      Hi There, Thanks for the advice. I think this is what was creating the problem and I am trying to fix it by reading the documentation I would ask for more help if needed. Thanks for the advice about posting the message. Cheers Nagesh
Re: Setting up Apache to execute .cgi file
by Popcorn Dave (Abbot) on Jul 29, 2005 at 01:59 UTC
    A couple of other things to check:

    1. Check your Apache logs! That went a long way in helping me when I was having the same problem.

    2. Check your shebang line. Are you using !/usr/bin/perl or something else? If you're on windows you're going to need something that points to where you have Perl on your system.

    Hope that helps!

    Useless trivia: In the 2004 Las Vegas phone book there are approximately 28 pages of ads for massage, but almost 200 for lawyers.