Apache2 CGI Execution Permission Denied
Asked Answered
B

3

1

I am getting this error when I try executing a basic Perl script on my Apache server. In my browser, I type in localhost/cgi-bin/first.pl, and I receive this error:

(13)Permission denied: exec of '/usr/lib/cgi-bin/first.pl' failed

This is my perl script:

#!/usr/lib/cgi-bin

print "Content-type: text/html\n\n";
print "Hello, World.";

And this is my default file in the sites-available folder. As you can see, every file in /usr/lib/cgi-bin should be recognized as a CGI file. And, /usr/lib/cgi-bin is exactly where first.pl is located.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

DocumentRoot /home/www
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /home/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AddHandler cgi-script .cgi .py
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

ALSO, I did do chmod a+x first.pl.

Bullion answered 27/5, 2014 at 2:18 Comment(1)
the shebang on the script isn't the location of the script... its the location of the interpreter for the script.Baccarat
P
1

You are getting this error because the shebang line (the first line of the script, starting with #!) specifies the interpreter that is launched to execute the script. What failed was therefore launching /usr/lib/cgi-bin as an executable.

Replace

#!/usr/lib/cgi-bin

with

#!/usr/bin/perl

If that still doesn't work, one possibility is that perl is in an ununsual location, and you could try

#!/usr/bin/env perl

One suggestion, if you can use a shell on the machine where your script lives, would be to try executing it directly. Had you done this, you would have seen a slightly more explanatory message "bad interpreter: Permission denied".

Parachronism answered 27/5, 2014 at 7:14 Comment(1)
That worked! Thank you! I changed it to #! /usr/bin/evn perl and it worked fineBullion
B
0

Check your permission/owner information on the directory as well.

Looking at the apache conf you posted, you will need to change the script to have a .cgi extension or add the perl extension to the AddHandler. What you have provided only lists the python extension.

Batsman answered 27/5, 2014 at 2:38 Comment(2)
Yeah, I just noticed that. Fixed it but still no luck.Bullion
I tried both a recursive chmod 755 and 777 on both my apache2 and cgi-bin folders as well, but I still get the same permission eror.Bullion
C
0

I had this problem with the http/cgi wrapper for git.

For me the issue was mod_cgid and the permissions on /var/run preventing cgid from attaching to the socket used for the cgi script.

The rather cryptic clue was

[Fri Nov 27 14:39:02.506675 2020] [cgid:error] [pid 589971:tid 140310986311424] (13)Permission denied: [client 172.16.90.189:50018] AH01257: unable to connect to cgi daemon after multiple tries: /usr/lib/git-core/git-http-backend

Yet www-data can run the git-http-backend cgi executable

I resolved this by creating folder /apache_run with permissions www_data:www_data 770 and adding the following to apache2.conf

ScriptSock /apache2_run/cgid.sock
Celin answered 27/11, 2020 at 14:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.