3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python3.5 + mod_wsgi + Apacheを Macで動かすメモ

Posted at

一時間くらい悩んだからメモ

mod_wsgiをインストール

pip3.5 install mod_wsgi

httpd.confに以下を追記(最下段でいい)

/etc/apache2/httpd.conf
LoadModule wsgi_module /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mod_wsgi/server/mod_wsgi-py35.cpython-35m-darwin.so
WSGIScriptAliasMatch ^/wsgi-bin/((?!(?i:webobjects)).*$) /your/wsgi/script/dir/$1 #テスト用のファイル置き場のpath

<Directory /your/wsgi/script/dir/>
Order deny,allow
Allow from all
</Directory>

この/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mod_wsgi/server/mod_wsgi-py35.cpython-35m-darwin.so
のpathをインストール時に把握しておく必要がある。これで詰まった。
バージョン変わったらモジュール名も変わると思う。

Apacheの再起動

sudo apachectl restart

httpd.confに設定したディレクトリにテストコードを置いて動作するか確認する

/your/wsgi/script/dir/test.py
def application(environ,start_response):
    status = '200 OK'
    response_header = [('Content-type', 'text/plain')]
    start_response(status, response_header)
    return [b"Hello World"]

権限付与忘れない

/your/wsgi/script/dir/
chmod 755 test.py

http://localhost/wsgi-bin/test.pyにブラウザからアクセスして
Hello Worldが出たらおっけー

3
4
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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?