LoginSignup
34
35

More than 5 years have passed since last update.

apacheでpythonを動かすまで

Last updated at Posted at 2015-02-07

起動停止

 macにはデフォルトでapacheが入っている。バージョンを調べる。

$ httpd -v
Server version: Apache/2.4.9 (Unix)
Server built:   Sep  9 2014 14:48:20

 起動、再起動の仕方。デフォルトは80ポートなので[ http://localhost ]。

$ sudo apachectrl start
$ sudo apachectrl stop

cgiを有効にする

 cgi_moduleを有効にする。コメントになっているのではずして再起動。

LoadModule cgi_module libexec/apache2/mod_cgi.so

パスを変更する

 httpd.confの中をみると、下記の設定になっている。

  • コンテンツは「/Library/WebServer/Documents」
  • CGIは「/Library/WebServer/CGI-Executables」

 「~/Web/doc」と「~/Web/cgi」を作って変えておく。

DocumentRoot "/Users/myname/Web/doc"
<Directory "/Users/myname/Web/doc">
...
</Directory>
<IfModule alias_module>
    ScriptAliasMatch ^/cgi-bin/((?!(?i:webobjects)).*$) "/Users/myname/Web/cgi/$1"
</IfModule>
#
<Directory "/Users/myname/Web/cgi">
...
</Directory>

確かめる

 あとは動作確認だけ。下記のようなpythonスクリプトを+xで作って「localhost/cgi-bin/test.py」にアクセスすればよい。

test.py
#!/usr/bin/python
print 'Content-Type: text/html\n\n'
print "Hello world!"
34
35
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
35