LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   cgi-bin error regarding perl script (https://www.linuxquestions.org/questions/linux-software-2/cgi-bin-error-regarding-perl-script-264367/)

hamish 12-09-2004 04:26 AM

cgi-bin error regarding perl script
 
Hey

I'm tring to get cgi working on my server at home, just so I can learn how to do it.

The setup is that the ScriptAlias is to my cgi-bin folder /usr/www/cgi-bin and that folder has <Directory> options:

Code:

<Directory /usr/www/cgi-bin>
        AllowOverride None
        Options +ExecCGI
        AddHandler cgi-script .cgi .pl
        SetHandler cgi-script
</Directory>

When I try and run my script, first.pl, i get an internal server error. Apache2's error is:

Code:

[Thu Dec 09 10:17:12 2004] [error] [client 10.0.0.1] (8)Exec format error: exec of '/usr/www/cgi-bin/first.pl' failed
[Thu Dec 09 10:17:12 2004] [error] [client 10.0.0.1] Premature end of script headers: first.pl

This is apparently quite a normal error.

I think I know how to get everything working, however, my qustion is to clarify how cgi is working.

When I set the Handler, should I have installed a seperate module, or is it installed by default, but turned off (I think my apache config turns it on)? Is it the cgi module which executes these files?


Secondly, do I need to install perl on my server, or is that also installed by default? If so, how does one turn it on?

The apache documentation suggested executing the first.pl file from the command line, which i did:
Code:

root@pi cgi-bin # ./first.pl
./first.pl: line 2: print: command not found
./first.pl: line 3: print: command not found

DOes this mean that perl is not installed on my server? I have seen a couple of references to Perl in the apache config file, but didn't touch them.

Any pointign in the right direction would be very much appreciated.

Thanks
hamish

bathory 12-09-2004 04:32 AM

To find out if you have perl installed and the correct path which is use at the beginning of the script, run:
Code:

which perl
To execute the script from the command line run:
Code:

perl first.pl
Mind tha you must also
Code:

chmod +x first.pl

hamish 12-09-2004 04:34 AM

Success! I get a response.

That means that perl is installed on the server.

Now I need to know why i get an internal server error with apache2. Do i have to tell apache where perl is on the machine, in order for it to work?

Hamish

hamish 12-09-2004 04:57 AM

Hey

I tried with an regular /bin/sh file, and it will work, however, my browser demands that i download the file (dater.sh) first and then it runs it.

How can I get arround this?

Hamish

bathory 12-09-2004 04:59 AM

There is no need to tell apache where perl is installed. Check your script for errors.

hamish 12-09-2004 05:37 AM

ok. I will check perl script.

Can you think of a reason that the regular /bin/sh executable would want to be downloaded before it ran? Instead of just running inside the open brower?

Excample: http://hamishnet.homelinux.com/cgi-bin/dater.sh

hamish

bathory 12-09-2004 05:59 AM

I'd guess that you have to add the .sh extension in the AddHandler directive

hamish 12-09-2004 07:14 AM

hey

I'm done that. but no luck.

hamish

bathory 12-09-2004 08:12 AM

Do you restart the server after you make the changes in httpd.conf?

hamish 12-09-2004 08:23 AM

yeah.

I have found some google sites saying that files can be downloaded and not executed if the server is configured not to execute the files. HOwever, i'm fairly sure it is correctly done:

I have:

script alias:
Code:

ScriptAlias /cgi-bin/ /usr/www/cgi-bin/
handler:
Code:

AddHandler cgi-script .cgi .sh
directory specific config
Code:

<Directory /usr/www/cgi-bin>
        AllowOverride All
        Options +ExecCGI
        AddHandler cgi-script .sh
        SetHandler cgi-script
        <IfModule mod_access.c>
              Order allow,deny
              Allow from all
        </IfModule>
</Directory>

Do you see any problems?

hamish

bathory 12-09-2004 08:48 AM

You don't need the AddHandler and SetHandler inside the <Directory...> because apache executes everything in that directory. In fact to test this I created a bash script inside the cgi-bin directory, made it executable and my apache (version 1.3.33) ran it like a charm.
Here is my Directory entry for the ScriptAlias directory:
Quote:

<Directory "/usr/local/apache/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

hamish 12-09-2004 10:16 AM

hey

i have done that now. I copied your code (and changed the directory path). I commented the "AddHandler cgi-script .cgi .sh" line.

However, it still seems to want to download it.

Really irritating me! It is so simple, I just can't understand what I'm doing wrong!

Hamish


All times are GMT -5. The time now is 08:19 AM.