Making Apache2 execute CGI scripts, globally?

Posted by fraktalisman on Mon 14 Apr 2008 at 12:08

I have set up a Debian etch system with apache2, perl etc, but I cannot get apache to actually execute my scripts..

I want to be able to have .pl executed everywhere below /var/www . Everything is installed from the regular Debian packages, and all packages have been updated yesterday.

I first modified /etc/apache2.conf adding:

AddHandler cgi-script .cgi .pl
Options +ExecCGI

But still get the error message "403 Forbidden" in the browser, and the following logged:

Options ExecCGI is off in this directory

When I put the AddHandler and Options directives once more for the actual subdirectory, after restarting apache, the scripts are served for downloading, instead of being executed!

In the error log, I see:

(2)No such file or directory: 
exec of '/var/www/auktionator/admin/_rechte.pl' failed
Premature end of script headers: _rechte.pl

The script is chmodded 0755, and so are the directories in /var/

drwxr-xr-x  4 root root  4096 2008-04-08 13:06 www

I can execute the script from the command line, as follows:

perl -cw /var/www/auktionator/admin/_rechte.pl

My perl script starts correctly with:

#! /usr/bin/perl

which is the actual location of my perl binary.

I wonder if perl is configured correctly for apache to find it. How and where would I check this? There is a perl.load in

/etc/apache2/mods-available

and a link to it in

/etc/apache2/mods-enabled


Posted by ajt (204.193.xx.xx) on Mon 14 Apr 2008 at 14:47
[ Send Message | View Weblogs ]
"Premature end of script headers" normally means that your Perl isn't good.

What does the Perl script look like? What does it output look like when you run it from the command line?

--
"It's Not Magic, It's Work"
Adam

[ Parent | Reply to this comment ]

Posted by Anonymous (84.45.xx.xx) on Mon 14 Apr 2008 at 22:51
/etc/apache2.conf

/etc/apache2/apache2.conf surely?

[ Parent | Reply to this comment ]

Posted by Anonymous (59.148.xx.xx) on Tue 15 Apr 2008 at 05:14
#!/usr/bin/perl
no space after #!

[ Parent | Reply to this comment ]

Posted by Anonymous (90.24.xx.xx) on Tue 15 Apr 2008 at 09:06
http://www.gnu.org/software/autoconf/manual/autoconf-2.57/html_ch apter/autoconf_10.html

Also, include a space after the exclamation point in interpreter specifications, like this:

#! /usr/bin/perl

If you omit the space before the path, then 4.2BSD based systems (such as DYNIX) will ignore the line, because they interpret `#! /' as a 4-byte magic number. Some old systems have quite small limits on the length of the `#!' line too, for instance 32 bytes (not including the newline) on SunOS 4.

[ Parent | Reply to this comment ]

Posted by Anonymous (212.114.xx.xx) on Tue 15 Apr 2008 at 15:55
Is the perl script executable? Does "/var/www/auktionator/admin/_rechte.pl" work (direct execution instead of perl ...)?
Does "ls -l /var/www/auktionator/admin/_rechte.pl" show something like rwxr-xr-x ?

All CGI-Scripts must be executable on the command line to work.

[ Parent | Reply to this comment ]

Posted by Anonymous (83.24.xx.xx) on Tue 15 Apr 2008 at 18:20
My shot: it's suexec that complaints about your access rights. Search for suexec Apache log and see what's going on. Suexec requires several security constraints to be met before script is executed.
-- Dariusz Cieslak

[ Parent | Reply to this comment ]

Posted by Anonymous (86.53.xx.xx) on Sat 19 Apr 2008 at 14:25
"(2)No such file or directory: "

That normally implies the interpreter can't be found -- you show that you can run the script with "perl -cw /path/to/script" (which ignores the shebang line) but can you also run it just as "/path/to/script" (which, like apache, will rely on the shebang line).

A common culprit for this is line endings. DOS (CRLF) or Mac (CR) line endings will will cause the shebang line to be incorrectly interpreted and give you exactly this error. Check the line endings using a decent editor (vim will tell you for example) or try a conversion program and see if the files are different after an attempted conversion. (dos2unix is in the tofrodos package, or you could use col, tr -d '\r' ... there are many possibilities)

Oh, and you'll get more immediate help if you jump on #debian on irc.debian.org.

[ Parent | Reply to this comment ]

Posted by Anonymous (212.244.xx.xx) on Mon 12 May 2008 at 08:29
How about chowning those files and dirs to www-data:www-data?

[ Parent | Reply to this comment ]

Posted by fraktalisman (82.207.xx.xx) on Tue 29 Apr 2008 at 14:14
[ Send Message ]
Thanks for the answers!

[ Parent | Reply to this comment ]

User Login

Username:

Password:

[ Advanced Login ]

Register Account

Quick Site Search