LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-09-2004, 04:26 AM   #1
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Rep: Reputation: 30
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
 
Old 12-09-2004, 04:32 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,158
Blog Entries: 1

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
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
 
Old 12-09-2004, 04:34 AM   #3
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Original Poster
Rep: Reputation: 30
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
 
Old 12-09-2004, 04:57 AM   #4
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Original Poster
Rep: Reputation: 30
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
 
Old 12-09-2004, 04:59 AM   #5
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,158
Blog Entries: 1

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
There is no need to tell apache where perl is installed. Check your script for errors.
 
Old 12-09-2004, 05:37 AM   #6
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Original Poster
Rep: Reputation: 30
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
 
Old 12-09-2004, 05:59 AM   #7
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,158
Blog Entries: 1

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
I'd guess that you have to add the .sh extension in the AddHandler directive
 
Old 12-09-2004, 07:14 AM   #8
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Original Poster
Rep: Reputation: 30
hey

I'm done that. but no luck.

hamish
 
Old 12-09-2004, 08:12 AM   #9
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,158
Blog Entries: 1

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
Do you restart the server after you make the changes in httpd.conf?
 
Old 12-09-2004, 08:23 AM   #10
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Original Poster
Rep: Reputation: 30
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
 
Old 12-09-2004, 08:48 AM   #11
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,158
Blog Entries: 1

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
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>
 
Old 12-09-2004, 10:16 AM   #12
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Original Poster
Rep: Reputation: 30
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cgi-bin script: turn off computer hamish Linux - General 2 10-21-2005 09:46 AM
Running perl scripts outside of cgi-bin ylikone Programming 1 09-08-2005 04:34 AM
trying to add cgi-bin perl script. shizzle Linux - Networking 7 05-19-2005 01:24 AM
.CGI scripts enabled with #!/usr/bin/perl -i?? computerdaves Fedora 8 02-18-2005 04:03 PM
#! does not seem to work in cgi-bin?? (script execution) servnov Linux - General 6 12-06-2004 07:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration