Apache CGI Configuration for Bash Script

      No Comments on Apache CGI Configuration for Bash Script

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/
<Directory "/usr/lib/cgi-bin">
	AllowOverride None
	Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
	Order allow,deny
	Allow from all
</Directory>

2- restart apache service

sudo service apache2 restart

3- enable cgi module

sudo a2enmod cgi

4- place a test.cgi file in /usr/lib/cgi-bin/

#!/bin/bash
 
echo "Content-type: text/html"
echo ""
echo "<html>"
echo "<head><title>hello</title></head>"
echo "<body>"
echo "hello world"
echo "</body>"
echo "</html>"

5- execute your script in the browser.

Share This!

Leave a Reply

Your email address will not be published.