Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I start to learn Python tonight...When I put python cgi script file under ~/Sites/, they can be executed via localhost/~USER_NAME/SCRIPT_FILE_NAME.py! 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 stackoverflow.com 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
add comment

1 Answer

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

(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
add comment

Your Answer

 
discard

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