2

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?

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

5 Comments

My CGI scripts end in .cgi, so I presume that's ... cgi-script cgi in my case? I'll test it now.
I noticed that these lines did not work if I placed them under the Directory section in the default file; they worked when I placed them into the main body of that file. I presume it would be better to place them into a .htaccess file rather, so that their effects are local to that folder only?
@SabreWolfy, well, I do usually myself place them into .htaccess where I need =) But I have other AddHandler directives within VirtualHost sections, so they both should work.
@SabreWolfy, what is the default file within Directory section?
The default file is in /etc/apache2/sites-available; in there is the <Directory> section which refers to /cgi-bin/ (which referred previously to the /usr/lib/cgi-bin folder). I have placed the lines into /var/www/cgi-bin/.htaccess and it is working. Thanks.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.