First (useful) thing I did was just post a simple "hello world" script in the cgi-bin:
#!/usr/bin/perl
# hello.pl -- my first perl script!
print "Content-type: text/html\n\n";
print <<"EOF";
<HTML>
<HEAD>
<TITLE>Hello, world!</TITLE>
</HEAD>
<BODY>
<H1>Hello, world!</H1>
</BODY>
</HTML>
EOF
Still forbidden. Made sure all permissions were 755 for directories and 644 for files. Played around with changing ownerships of various files to and from root:root, myusername:www-data.
Someone at Linode (web hosting) recommended using to check file permissions:
sudo apt-get install tree
tree -puf /usr/lib | grep cgi
tree -puf /var/www
Shows a tree of files, ownerships and permissions. Cool!
Checked Apache error log:
$ sudo cat /var/log/apache2/error.log
Hmmm:
[Sat Jun 06 05:53:24.412867 2015] [authz_core:error] [pid 28374:tid 140381836453632] [client 108.205.62.183:55886] AH01630: client denied by server configuration: /usr/local/apache2
Posted a more useful question, joined the Debian email list and was referred to the docs: /usr/share/doc/apache2/README.Debian then got the following SO response:
That means you haven't configured authorization for your webserver.
What you want to do is ensure that you have something like
<Directory /usr/local/apache2/cgi-bin>
Require all granted
</Directory>
Note that in Debian, there's an advanced configuration system which would have done all of this for you, if you would have used it ;-)
To do so, first remove (or comment out) the things you've already added. Then:
a2enmod cgi
service apache2 restart
Commented out the changes AWStats had made, ran a2enmod, restarted and 'Hello World' worked. Reinstated the AWStats configuration changes to etc/apache2/apache2.conf:
#
# Directives to allow use of AWStats as a CGI
#
Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"
#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory "/usr/local/awstats/wwwroot">
Options None
#Options Index FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And there's AWStats in the browser. Awesome.