LoginSignup
0
1

More than 5 years have passed since last update.

mod_wsgiの"Compiled for ~" warning について

Last updated at Posted at 2017-03-12

mod_wsgiをlibapache2-mod-wsgiでインストールすると、一つ落とし穴があります。
以下のコマンドでLogファイルを確認してください。

vim /var/log/apache2/error.log

きっと、このようなwarning(環境によってやや異なると思います)が記述されているのではないでしょうか

[Mon Feb 13 14:10:22.233656 2017] [wsgi:warn] [pid 10526:tid 139972854908800] mod_wsgi: Compiled for Python/2.7.8.
[Mon Feb 13 14:10:22.233725 2017] [wsgi:warn] [pid 10526:tid 139972854908800] mod_wsgi: Runtime using Python/2.7.9.

これは、文字通りwsgiをコンパイルしたpythonと現在使用されているpythonのバージョンが違うよ、と言っています。

ということで、これを解決するために、pipを使ってmod_wsgiをインストールし直します。
ただ、その前にpyenvをインストールしてください。

pip install mod_wsgi

すると、このようなファイルが作成されます

/home/USERNAME/.pyenv/versions/3.5.2/lib/python3.5/site-packages/mod_wsgi/server/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so

apache2がこのファイルを読みにいくように設定ファイルを変更します。

sudo vim /etc/apache2/mods-available/wsgi.load

moduleのパスを記載します。先ほどインストールしたpyenvのモジュールを指定してください。
(なお、USERNAMEの変更を忘れないでください)

LoadModule wsgi_module /home/USERNAME/.pyenv/versions/3.5.2/lib/python3.5/site-packages/mod_wsgi/server/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so

上記を行なった上でapache2を再起動します。

sudo service apache2 restart

これで再度(ドメイン名、またはIPアドレス)/test_wsgiにアクセスするとHello Worldが描画され、Warningは発生しなくなるはずです。

なお、ubuntuで進めていると、ubuntuのバグ(command-not-found fails when user-installed python3 is in PATH)によりImportError: No module named '_sysconfigdata_m'が発生しますので、Debianを推奨します。

0
1
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
0
1