The Quick Way
Install the Apache web server
In the command line (Terminal) application:
sudo apt-get install apache2
Make your script executable by Apache
For this example we'll assume the CGI script is named
test.sh and is saved in your personal home folder. For Apache to use
test.sh, the script first needs to have executable permissions:
chmod 755 $HOME/test.sh
It also needs to be moved to the Apache-designated CGI folder. For Ubuntu (and other Debian-based operating systems), this is
/usr/lib/cgi-bin/, while HTML and other content is stored in
sudo mv $HOME/test.sh /usr/lib/cgi-bin/
Visit the output at your local server
Apache will serve the
test.sh-generated HTML at http://localhost/cgi-bin/test.sh. If Apache is located somewhere besides your own machine, replace 'localhost' with the URL or IP address of the server.
Storing CGI scripts in /var/www/test-cgi rather than /usr/lib/cgi-bin/
You need to modify the vanilla Apache configuration to store CGI scripts at another folder.
Add the following inside the
ScriptAlias /test-cgi/ /var/www/test-cgi/
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Allow from all
Then, in the command line:
sudo mkdir /var/www/test-cgi
Then, in the command line, restart Apache:
sudo apachectl restart
As with The Quick Way, the CGI output should be served at http://localhost/test-cgi/test.sh (replace "localhost" with the server domain if you're developing remotely).
If you have problems, consult the official Apache documentation.