Firstly, I would not run CGI from your /home/
directory. Permissions are not set up for that, for web servers, and can lead to some headaches at times, both with permissions configurations and other issues.
Secondly, I would suggest *creating a dedicated directory within /var/www/
(such as cgi-bin
) where your CGI scripts get put, and use that in the Apache configuration.
sudo mkdir -p /var/www/cgi-bin/
sudo chown $USER:www-data /var/www/cgi-bin/
The above commands will create the directory and set up permissions so that you can write to the directory, and the webserver can read the directory and have access to do things inside the directory.
From there, drop your CGI there, make sure it's owned in a similar way (sudo chown $USER:www-data /var/www/cgi-bin/*
) and then set your Apache configuration to use /var/www/cgi-bin
instead of /home/router/cgi-bin
.
If for some reason you must use /home/router/cgi-bin
, then you need to do several things: permit www-data and all users to traverse up to the cgi-bin
directory, and give www-data access to the directory itself.
sudo chgrp www-data /home/router/cgi-bin
sudo chmod +rx /home/
sudo chmod +rx /home/router/
sudo chmod 750 /home/router/cgi-bin/
The problem with this is you have to open your home directory just enough so that the 'other' category of users can reach into the directory structure and traverse it. This is a security hole, because any other user shouldn't be permitted to traverse the file system into your home directory in this way, as it could lead to data leakage or theft of personal data. (This is why most guides for web servers suggest NOT using home directories, and instead dedicated directories in /srv/
or /var/www/
for web server document directories)