macOS 10.13.5/python3.6.5/Apache2.4.33
発生している問題・エラーメッセージ
Apacheを起動し、http://localhost:8080/cgi-bin/test.pyにアクセスしてtest.pyファイルをブラウザ上で開きたいのですが、Internal Server Errorとなり表示されません。
error_logを見たところ、(8)Exec format errorが原因と考えられたため、調べられる範囲で対処法を試してみましたが、解決には至っておりません。
エラーの原因が分かる方がございましたら、ご指摘いただけると非常に助かります。
初学者ゆえに、初歩的な部分が抜けている可能性もございますが、何卒よろしくお願い致します。
test.pyのソースコード
python
1#!/Users/(ユーザー名)/.pyenv/shims/python 2 3print ('Content-Type: text/html\n\n') 4print ("Hello world!")
ディレクトリ構造は以下の通りです。
[www]
. ├[cgi-bin]
. ├test.py
. ├test.pl
. └test.html
. └index.html
test.plとtest.htmlはブラウザ上で表示されましたが、test.pyのみInternal Server Errorの状態です。
試したこと
・パーミッションの変更
cgi-binおよびtest.pyは$ chmod 755 でパーミッションを変更しました。
($ ls -al でパーミッションが変更されていることも確認しております)
・設定の変更(httpd.conf書き換え)
.#LoadModule cgi_module libexec/apache2/mod_cgi.so
.#AddHandler cgi-script .cgi
コメントアウトになっている上2つの#を消しました。
<Directory "/usr/local/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
AddHandler cgi-script .py .pyc
AddHandler text/html .html .txt
</Directory>
太字部分を追加致しました。
・ScriptAriasの設定
ScriptAlias /cgi-bin/ "/usr/local/var/www/cgi-bin/"
・su www実行時の内容
$ su root Password: sh-3.2# su www sh-3.2# id uid=0(root) gid=0(wheel) groups=0(wheel),1(daemon),2(kmem),3(sys),4(tty),5(operator),8(procview),9(procmod),12(everyone),20(staff),29(certusers),61(localaccounts),80(admin),33(_appstore),98(_lpadmin),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh),701(com.apple.sharepoint.group.1) sh-3.2# python test.py Content-Type: text/html Hello world!
$ su root Password: sh-3.2# su www -s /usr/local/var/www/cgi-bin/test.py sh-3.2#
$ su root Password: sh-3.2# su www -s /bin/sh sh-3.2# id uid=0(root) gid=0(wheel) groups=0(wheel),1(daemon),2(kmem),3(sys),4(tty),5(operator),8(procview),9(procmod),12(everyone),20(staff),29(certusers),61(localaccounts),80(admin),33(_appstore),98(_lpadmin),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh),701(com.apple.sharepoint.group.1) sh-3.2# /usr/local/var/www/cgi-bin/test.py /usr/local/var/www/cgi-bin/test.py: line 3: syntax error near unexpected token `'Content-Type: text/html\n\n'' /usr/local/var/www/cgi-bin/test.py: line 3: `print ('Content-Type: text/html\n\n')' sh-3.2#
$ su root Password: sh-3.2# su www -s /bin/sh sh-3.2# /Users/(ユーザー)/.pyenv/shims/python -V Python 3.6.5 sh-3.2#
$ su root Password: bash-3.2# chsh -s /bin/bash www Changing shell for _www. bash-3.2# su www bash-3.2$ id uid=70(_www) gid=70(_www) groups=70(_www),12(everyone),61(localaccounts),100(_lpoperator),701(com.apple.sharepoint.group.1) bash-3.2$ cat /Users/(user)/.pyenv/shims/python #!/usr/bin/env bash set -e [ -n "$PYENV_DEBUG" ] && set -x program="${0##*/}" if [[ "$program" = "python"* ]]; then for arg; do case "$arg" in -c* | -- ) break ;; */* ) if [ -f "$arg" ]; then export PYENV_FILE_ARG="$arg" break fi ;; esac done fi export PYENV_ROOT="/Users/(user)/.pyenv" exec "/Users/(user)/.pyenv/libexec/pyenv" exec "$program" "$@" bash-3.2$ /Users/(user)/.pyenv/shims/python -V Python 3.6.5 bash-3.2$
$ /usr/local/var/www/cgi-bin/test.py /usr/local/var/www/cgi-bin/test.py: line 3: syntax error near unexpected token `'Content-Type: text/html\n\n'' /usr/local/var/www/cgi-bin/test.py: line 3: `print ('Content-Type: text/html\n\n')'
・lsコマンドの結果
drwxr-xr-x+ 32 (ユーザー名) staff 1024 7 5 13:29 /Users/(ユーザー名) drwxr-xr-x 26 (ユーザー名) staff 832 7 2 21:23 /Users/(ユーザー名)/.pyenv drwxr-xr-x 31 (ユーザー名) staff 992 7 5 14:28 /Users/(ユーザー名)/.pyenv/shims/ -rwxr-xr-x@ 1 (ユーザー名) staff 422 6 9 19:59 /Users/(ユーザー名)/.pyenv/shims/python
回答2件
あなたの回答
tips
プレビュー