Running CGI With Perl under Apache Permission Problem
Make sure you have a <Directory> section for the cgi-bin directory. And make sure "allow from all" is in it.
<Directory /var/www/mychosendir/cgi-bin>
Options +ExecCGI -Indexes
allow from all
</Directory>
Also...your ScriptAlias is for /cgi-bin/. Your URL is /mychosendir/cgi-bin. Unless you have some rewrite magic going on, your url should probably be http://my.host.com/cgi-bin/test.cgi , or you'll need to change your ScriptAlias line to look like
ScriptAlias /mychosendir/cgi-bin/ /var/www/mychosendir/cgi-bin
The error you posted in your update, sounds like you don't have a #! line at the beginning of your script. You'll need one, and it should look like
#!/path/to/your/perl
Related videos on Youtube
neversaint
Updated on September 17, 2022Comments
-
neversaint over 1 year
I have the following entry under
apache2.conf
in my Debian box.AddHandler cgi-script .cgi .pl Options +ExecCGI ScriptAlias /cgi-bin/ /var/www/mychosendir/cgi-bin/ <Directory /var/www/mychosendir/cgi-bin> Options +ExecCGI -Indexes allow from all </Directory>
Then I have a perl cgi script stored under these directories and permissions:
nvs@somename:/var/www/mychosendir$ ls -lhR .: total 12K drwxr-xr-x 2 nvs nvs 4.0K 2010-04-21 13:42 cgi-bin ./cgi-bin: total 4.0K -rwxr-xr-x 1 nvs nvs 90 2010-04-21 13:40 test.cgi
However when I tried to access it in the web browser:
http://myhost.com/mychosendir/cgi-bin/test.cgi
They gave me this error:
[Wed Apr 21 15:26:09 2010] [error] [client 150.82.219.158] (8)Exec format error: exec of '/var/www/mychosendir/cgi-bin/test.cgi' failed [Wed Apr 21 15:26:09 2010] [error] [client 150.82.219.158] Premature end of script headers: test.cgi
What's wrong with it?
Update:
I also have the following entry in my
apache2.conf
:<Files ~ "^\.ht"> Order allow,deny Deny from all </Files>
And the content of
test.cgi
is this:#!/usr/bin/perl -wT print "Content-type: text/html\n\n"; print "Hello, world!\n";
-
neversaint about 14 years@cHao: Sorry I don't get it. As I pointed out in OP I already have
cgi-bin
directory with the right permisson (a+x). -
neversaint about 14 yearsHow do I check and enable that?
-
Michalis about 14 yearsThe directory is there, but unless you have a section in the config file that grants access to it, Apache won't let you see it.
-
neversaint about 14 years@cHao: Thanks but how can I change the config to grant access?
-
Michalis about 14 yearsUpdated my answer. Reread. :)
-
neversaint about 14 yearsI modified the Script alias to
ScriptAlias /var/www/mychosendir/cgi-bin/ /var/www/mychosendir/cgi-bin/
and add the<Directory>
section exactly like yours. But now it give internal server error instead. And BTW, I do really want my url to behttp://myhost.com/mychosendir/cgi-bin/test.cgi
instead of removing themychosendir
. -
Michalis about 14 yearsThe first thing in the ScriptAlias directive is the url you want to refer to that directory. So you'll probably want to get rid of the first /var/www in your ScriptAlias line.
-
neversaint about 14 yearsIt does have. See my update on the test.cgi code.
-
neversaint about 14 yearsYou mean like this:
ScriptAlias /mychosendir/cgi-bin/ /cgi-bin/
. Sorry please be patient with me. -
Htbaa about 14 yearsFirst find out as which user Apache is running. This can be done by checking your
httpd.conf
orapache2.conf
- look for the User and Group settings. Next,ls -al /var/www/mychosendir/cgi-bin
to see the permissions and file owner. The user under which Apache is running must have access to these files. They should also contain the execute bit. -
neversaint about 14 yearsI really want it to be accessed here:
http://myhost.com/mychosendir/cgi-bin/test.cgi
. Then how should I modify the ScriptAlias? I also tried thisScriptAlias /cgi-bin/ /mychosendir/cgi-bin/
but internal server error. -
Michalis about 14 yearsI mean like this: ScriptAlias /mychosendir/cgi-bin/ /var/www/mychosendir/cgi-bin/
-
Michalis about 14 yearsI see it. I'm running the same code on one of my servers right now, so IF your perl is at /usr/bin/perl, then the script should be fine.