April 19, 2012

MacのWeb共有でPythonのCGIを実行する環境


  1. ユーザhogeが~/Sites以下での実行環境 .pyで実行する場合
  2. Uncheck System Preferences > Sharing > Web Shearing
  3. % diff /etc/apache2/httpd.conf /etc/apache2/httpd.conf.default
    145c145
    < LoadModule python_module libexec/apache2/mod_python.so
    ---
    > #LoadModule python_module libexec/apache2/mod_python.so
    469c469
    <     AddHandler cgi-script .cgi .py
    ---
    >     #AddHandler cgi-script .cgi
  4. % diff /etc/apache2/users/hoge.conf /etc/apache2/users/hoge.conf.default
    2c2
    <     Options Indexes MultiViews ExecCGI
    ---
    >     Options Indexes MultiViews
  5. Check System Preferences > Sharing > Web Shearing
  6. /Users/hoge/Sites% cat hello.py
    #!/usr/bin/python
    # -*- coding: utf-8 -*-

    print "Content-Type: text/plain"
    print
    print "Hello world!"
    /Users/hoge/Sites% chmod 755 hello.py
  7. http://localhost/~hoge/hello.py にアクセスするとHello world!と表示される

No comments:

Post a Comment