If you’re constantly writing scripts in bash, at some point you will want to access your script from the web, and that’s where CGI bash script comes in handy. Here’s how to configure apache in any debian distribution for running CGI bash scripts.
1- open /etc/apache2/sites-available/default and add the following text.
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Allow from all
2- restart apache service
sudo service apache2 restart
3- enable cgi module
4- place a test.cgi file in /usr/lib/cgi-bin/
echo "Content-type: text/html"
echo "hello world"
5- execute your script in the browser.