For your web browser to notice that the file should be executed instead of just sent over the web you need to make it executable and give it a proper extension. To make it executable, place the script in the cgi-bin directory and chmod a+x scriptfile
The extension (eg .cgi) depends on your httpd.conf
Check your httpd.conf file:
First of all, you need to add a directory directive for the cgi-bin directory, for instance:
AddHandler cgi-script .cgi .pl
allow from all
should your scripts be placed in /srv/www/cgi-bin.
Giving it cgiexec permission you allow script execution from that directory (/srv/www/cgi-bin en this example); the AddHandler line just tells apache to consider executable files those which end with .cgi and .pl (you can put what ever extension you like here, your script files must end with any one of this extensions).
Finally, I added an allow from all
so anyone could access the script.
You also need to specify which directories contain server scripts, to do this just edit the line ScriptAlias (also in httpd.conf) to point to where you placed the cgi executable, in this example it would be something like:
ScriptAlias /cgi-bin/ "/srv/www/cgi-bin/"
so, when someone types in his browser http://www.yourserver.org/cgi-bin
, apache will know he's refering to /srv/www/cgi-bin
Hope you find it useful.