Ubuntu – CGI-Bin does not seem to be set up


I've used tasksel and installed LAMP server.
But I can't seem to figure if Cgi-bin is set up.
There is no Cgi-bin in the web root folder.
And when I try and call a test.py file from the browser, it downloads it rather than
executes it.

I've had a look at various how-to's but i'm still no closer.

Ubuntu 14.04
Apache 2.4.7 (Apr 3 2014)

Best Answer

According to Apache documentation

The ScriptAlias directive has the same behavior as the Alias directive, except that in addition it marks the target directory as containing CGI scripts that will be processed by mod_cgi's cgi-script handler. URLs with a case-sensitive (%-decoded) path beginning with URL-path will be mapped to scripts beginning with the second argument, which is a full pathname in the local filesystem.

The ScriptAlias directive looks like:

   ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/

It means that if you Request URL http://mydomain/cgi-bin/myscript.py Apache tries to run /usr/local/apache2/cgi-bin/myscript.py

The ScriptAlias directive tells Apache that a particular directory is set aside for CGI programs. Apache will assume that every file in this directory is a CGI program, and will attempt to execute it, when that particular resource is requested by a client.

ScriptAlias directive is in default apache2.conf configuration file and it works if mod_cgi is enabled and myscript.py is executable and return proper output.

If you have a different configuration, you should read: Apache Tutorial: Dynamic Content with CGI

Related Question