SabreWolfy
SabreWolfy

Reputation: 5540

Execute Python CGI from /cgi-bin/ folder

I have a standard Apache2 installation on an Ubuntu server. The default settings use ScriptAlias to refer /cgi-bin/ to /usr/lib/cgi-bin/. If I place my Python CGI script in /usr/lib/cgi-bin/ it executes.

I created /var/www/cgi-bin/ with appropriate permissions, removed the ScriptAlias line, changed the Directory entry in the default file for the site, moved the CGI file to /var/www/cgi-bin/ and restarted Apache2, but I was not able to get the script to run. It was appearing as a text file in the browser instead of being executed. The HTML file calling the script refers to /cgi-bin/SCRIPT, so I left that unchanged. I tried variations on /cgi-bin and /var/www/cgi-bin in the config files without success. How can I get a Python CGI file to run from /var/www/cgi-bin?

Upvotes: 2

Views: 3948

Answers (2)

guinny
guinny

Reputation: 1532

please make sure:

  1. the file you are calling itself has enough permission
  2. the file you are calling has an extension that is is in the .htaccess file (see newtover's answer)
  3. specify how you want to run the script in the first line of the file. If you are calling foo.pl, make sure #!/usr/bin/perl is in the first line.

Upvotes: 0

newtover
newtover

Reputation: 32094

If you removed the ScriptAlias directive, you should probably add the following lines into the main config for the directory or into .htaccess file:

Options +ExecCGI
AddHandler cgi-script py

Upvotes: 4

Related Questions