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
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
5 Comments
cgi-script cgi in my case? I'll test it now.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?.htaccess where I need =) But I have other AddHandler directives within VirtualHost sections, so they both should work.default file within Directory section?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.please make sure:
- the file you are calling itself has enough permission
- the file you are calling has an extension that is is in the .htaccess file (see newtover's answer)
- 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.