Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I start to learn Python tonight...When I put python cgi script file under ~/Sites/, they can be executed via localhost/~USER_NAME/! But my project root is not under Sites/, so every time I need copy the scripts file to Sites for test. Question is - can I update Apache conf, so that the web server can load scripts from my project src folder directly?

I've tried to edit /etc/apache2/users/USER_NAME.conf, and replace /Users/USER_NAME/Sites/ with /Users/USER_NAME/PATH_TO_PROJECT_SRC/. But I always met with 'Permission Denied' error then.

Can somebody tell me what's wrong and how to fix it? By the way, what's the best practice for python cgi script development?

Thanks a lot!

share|improve this question

migrated from Jan 21 '13 at 18:40

This question came from our site for professional and enthusiast programmers.

The "best practice" is not to use cgi at all. – Daniel Roseman Jan 21 '13 at 17:26

First of all, make sure that Apache is running. The URL http://localhost should return 'It works!'. If not, then enable Apache:

sudo apachectl start

Now enable Sites: create the file /etc/apache2/users/$USER.conf with the following content:

<Directory "/Users/$USER/Sites/">
    Options Indexes MultiViews FollowSymLinks ExecCGI
    AddHandler cgi-script .cgi
    AllowOverride All
    Order allow,deny
    Allow from all

(where $USER is your short user name). Then execute sudo apachectl restart. The URL http://localhost/~$USER now should return a nice webpage.

The config file above instructs Apache to follow symlinks. Simply create a symlink to your Python script in your development directory. No need to copy things around.

share|improve this answer

You must log in to answer this question.