I have a local Apache2 server (installed with LAMP). The Apache2 directory is /etc/apache2 and my document root is /var/www. Under the doc root, there's a /cgi-bin directory, in which my script cgi.pyis. Executing with ./cgi.py gives the desired output, but when I point my web browser to the file it offers me to download it. Apparently this is often due to an access problem, but after adding a+x permissions to the file the problem remains.

Here's the simple script:

# -*- coding: UTF-8 -*-

#enable debugging
import cgitb

print("Content-Type: text/plain;charset=utf-8");

print("Hello World!");

In the apache2 directory's httpd.conf I've added the follow (it was empty prior to it):

ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory /var/www/cgi-bin/>
    Options ExecCGI
    AddHandler cgi-script .cgi .py

What could be the reason the script won't execute?

EDIT: Rookie mistake, I didn't restart the server after making changes to httpd.conf. After doing that the script executed. Thanks to Jenny D for suggesting it.

  • Did you restart apache or reload its configuration after editing httpd.conf?
    – Jenny D
    Feb 20, 2013 at 10:43
  • @JennyD Now that's a good starting point -- it made things different. Got an error at first, but it was only because I had changed the formatting slightly. Thanks! :)
    – 5th
    Feb 20, 2013 at 10:55
  • Just saw your edit. It may be a rookie mistake, but having been a sysadmin for nigh on 20 years, I've done it not too long ago too... it happens to all of us.
    – Jenny D
    Feb 20, 2013 at 11:10

1 Answer 1


The server will only read its configuration file on startup, or when you specifically tell it to reload it. After changing the httpd.conf you need to either restart the server or reload the configuration (either by running apachectl restart, or by running service httpd reload, or something else depending on your operating system/setup).

If you want to have a config that is reread without restarting the server, there is htaccess. However, since that means that apache will re-check the file for every connection, it will slow the server down a bit. Whether that is a problem will of course depend on how great a load the server has to start with.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .