Edit: This question has been wrongly marked as a duplicate of How can I troubleshoot my Perl CGI script?, that question deals with how to debug a perl program and the answers explain how to do that. In this case I did not even get as far as that, and the problem turned out to be a apache configuration issue, where I had used a relative path in the Directory directive, none of these these things are mentioned in the answers to that question.
Original Question: I have set up an ubuntu test server (16.04.2 LTS) and are trying to get apache on it to execute a perl cgi script. It runs fine from the command line, but in the browser it always display the source code. I have gone through many pages of advice both on this site and others, but I cannot get it to work, so any help would be greatly appreciated.
My site's conf file looks like this (I want to be able to execute scripts on a per directory basis):
<VirtualHost *:443>
DocumentRoot "/var/www/test"
ServerName mydomain.org
<Directory "/var/www/test">
allow from all
Options None
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile /etc/webmin/letsencrypt-cert.pem
SSLCertificateKeyFile /etc/webmin/letsencrypt-key.pem
SSLCACertificateFile /etc/webmin/letsencrypt-ca.pem
<Directory "path/to/dir">
Options ExecCGI Indexes
AddHandler cgi-script .pl
</Directory>
</VirtualHost>
My mods-enabled directory looks like this:
access_compat.load autoindex.conf mime.conf setenvif.load
alias.conf autoindex.load mime.load socache_shmcb.load
alias.load cgi.load mpm_prefork.conf ssl.conf
auth_basic.load deflate.conf mpm_prefork.load ssl.load
authn_core.load deflate.load negotiation.conf status.conf
authn_file.load dir.conf negotiation.load status.load
authz_core.load dir.load php7.0.conf
authz_host.load env.load php7.0.load
authz_user.load filter.load setenvif.conf
There are no errors in the error.log and the access logs tells me:
mydomain.org:443 xx.xxx.xxx.xx - - [27/Apr/2017:10:37:02 +0100] "GET /path/to/dir/test.pl HTTP/1.1" 304 3921 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"
The script (test.pl) is simply this, and works from the command line:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, world!\n";
Can anyone tell me what I am doing wrong here?