Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

#enable debugging
import cgitb
cgitb.enable()

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

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
</Directory>

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.

share|improve this question
    
Did you restart apache or reload its configuration after editing httpd.conf? –  Jenny D Feb 20 '13 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 '13 at 10:55
    
I'll make that comment into an answer then so you can accept it! –  Jenny D Feb 20 '13 at 11:02
    
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 '13 at 11:10

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.