Apache2 CGI Execution Permission Denied

别说谁变了你拦得住时间么 提交于 2021-02-16 15:11:33

问题


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.


回答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".




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/23880130/apache2-cgi-execution-permission-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!