Search code examples
apacheperlcgirhel

Simple cgi script fails with permission denied error


Perl CGI script fails with

Can't locate /home/testdir/first.pl:  /home/testdir/first.pl:  
Permission denied at /var/www/cgi-bin/first.cgi line 2.

and

End of script output before headers: first.cgi  in /etc/httpd/logs/error_log

This is an rhel8 system with apache 2.4

I have tried moving first.pl around to different locations and modifying first.cgi to point to first.pl. first.cgi executes if I place first.pl in /var/www, but not /home/testdir, /var or other directories

In httpd.conf, I set permissions for /home/testdir/ to the same as /var/www, shown below, and restarted apache

<Directory "/home/testdir">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

Out of frustration, I then changed the permissions for /var/www to Require all denied and restarted apache. first.cgi still successfully ran first.pl when I pointed it to /var/www with the permissions changed to Require all denied.

I also disable suexec and recieved the same errors when pointing first.cgi to /home/testdir

The permissions for first.pl are 755 in /home/testdir as well as /var/www and the user and group are both root.

The permissions for home, testdir, var and www are all 755 and the users and groups are all root

first.cgi:

#!/usr/bin/perl
require '/home/testdir/first.pl';
test();

first.pl:

#!/usr/bin/perl
sub test{
    print "Content-type: text/html\n\n";
    print "Hello, World.";
}
first;

The script should display "Hello, World". on the webpage. Instead, it displays:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Solution

  • Dave Mitchell's comment is correct. After entering sudo setenforce permissive on the command line, the script runs as expected.