So, I'm new to CGI / Perl, I'm trying to move a perl-based web app to a new server.
My new server is CentOS 7, which runs Apache HTTPD 2.4.6.
I'm trying to get a basic Perl CGI working from an HTTP request.
The web request is returning "500 Internal Server Error"
The error log is showing "permission denied":
[Tue May 12 16:56:44.604660 2015] [cgi:error] [pid 12302] [client 10.0.2.2:56693] AH01215: (13)Permission denied: exec of '/var/www/html/cgi-test/first.pl' failed
[Tue May 12 16:56:44.604708 2015] [cgi:error] [pid 12302] [client 10.0.2.2:56693] End of script output before headers: first.pl
My CGI script is in /var/www/html/cgi-test/first.pl
It looks like this:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, World.";
In the cgi-test directory the permissions look like this:
drwxr-xr-x. 2 root root 21 May 12 16:48 .
drwxr-xr-x. 4 root root 32 May 12 16:48 ..
-r-xr-xr-x. 1 root root 76 May 12 16:48 first.pl
Perl is in the normal place and has I think normal permissions
[root@localhost cgi-test]# ls -al /usr/bin/perl
-rwxr-xr-x. 2 root root 11400 Mar 6 05:07 /usr/bin/perl
My httpd.conf is the default. I've just added the following section in order to allow cgi in my cgi-test directory:
<Directory "/var/www/html/cgi-test">
Options +ExecCGI
AddHandler cgi-script .cgi .pl
</Directory>
To eliminate the possibility of suexec being the cause of this issue I've moved it from /usr/sbin/suexec to another file name.
Httpd is running as user "apache" which is in group "apache"
[root@localhost cgi-test]# ps -Af | grep httpd
root 12298 1 0 16:56 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 12299 12298 0 16:56 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 12300 12298 0 16:56 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 12301 12298 0 16:56 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 12302 12298 0 16:56 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 12303 12298 0 16:56 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 12342 12260 0 17:20 pts/0 00:00:00 grep --color=auto httpd
[root@localhost cgi-test]# groups apache
apache : apache
I have tried running the script as apache, it works without any problem.
[root@localhost cgi-test]# su -s /bin/bash apache
bash-4.2$ perl /var/www/html/cgi-test/first.pl
Content-type: text/html
Hello, World.bash-4.2$
Presumably I'm hitting some security precaution of Apache. Lots of conflicting advice about what this might be. Any help much appreciated.