0

I spent hours and hours trying to fix an Internal Server Error on a perl program. I distilled the program down to the very simplest, and nothing would work. In fact, here's the entire program:

#!/usr/local/bin/perl

use strict;
print "Content-type: text/html\n\n";
print <<"thepage";
<html><head><title>Test</title></head><body>
<p>help</p>
</body></html>
thepage

Couldn't get it to work. Permissions correct. Same directory where I have literally a hundred other scripts running constantly. httpd.conf fine. It runs from the command line when SSHing into the server. Error message says:

[Mon May 18 09:59:29 2020] [error] [client 98.190.183.148] (13)Permission denied: exec of '/data/www/facialsurgery/root/cgi-bin/test_print_2.pl' failed
[Mon May 18 09:59:29 2020] [error] [client 98.190.183.148] Premature end of script headers: test_print_2.pl

But I fixed it! By adding "-w" to the shebang line, so the line says:

#!/usr/local/bin/perl -w

But I have, as I mentioned, many many programs running fine without the -w. What can I do to trace this down more, so I don't eventually run into more trouble with more important programs?? Thanks so much for any insight in this.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
user533604
  • 19
  • 1
  • 4
  • 1
    The error message is pretty explicit. What is the current filemode on that `.pl` file? When you added `-w` did you also do a `chmod +x` on it? – Jim Garrison May 18 '20 at 17:37
  • Hi, Jim, I did not do chmod. The file was already 777, I know, too much permission, but I was debugging. All the directory permissions above were good, too. The file was in a directory where ~100 other scripts were operating. I went back and forth: I put in the "-w", and it worked. I took out the "-w", and it gave Server Error. Totally consistent. I'm baffled. As I mentioned, lot of other perl scripts did not have -w on shebang. It wasn't my habit. – user533604 May 18 '20 at 18:39
  • Do you have selinux enabled? – Jim Garrison May 18 '20 at 20:27
  • Actually, this is the first I've heard of selinux, so I don't believe I do. – user533604 May 18 '20 at 21:10

1 Answers1

0

The error:

(13)Permission denied: exec of '/data/www/facialsurgery/root/cgi-bin/test_print_2.pl' failed

This means that the web server (Apache) wasn't able to execute the script due to a permission error. (13 is error number for Permission denied.) This has nothing to do with presence or absence of -w.[1]

First, determine as which user the web server (Apache) runs. For the remainder of this post, I'm going to assume it's the default, www-data.

Then, make sure the following file is readable (grants the r permission) and executable (x) by the www-data user (or its group):

  • /data/www/facialsurgery/root/cgi-bin/test_print_2.pl

This includes making sure the following directories are accessible (x) by the www-data user (or its group):

  • /data/www/facialsurgery/root/cgi-bin
  • /data/www/facialsurgery/root
  • /data/www/facialsurgery
  • /data/www
  • /data

If there's no problem with the permissions of those, you could also be running afoul or volume-wide limitations (e.g. noexec attribute on the value) or other security measures (e.g. SELinux restrictions)


  1. I think that ancient systems used to treat everything after the shebang (#!) as the command to execute. On such a system, the kernel would try to execute the non-existent file /usr/local/bin/perl -w. But that would result in errno 2 (No such file or directory), and I don't believe any modern system does this.
ikegami
  • 367,544
  • 15
  • 269
  • 518