実現したいこと
Apache上でFlaskアプリケーションを動作させるようにしたい。
- http: //localhost/FlaskApp1/ というURLでアプリケーションを公開したい。
※自動ハイパーリンクにならないよう意図的に半角スペースを入れています。
前提
Pythonの勉強を初めて、Flaskアプリケーションというものを知りまして、app.runが出来るようになった
(ポート番号を指定しての単品アプリ起動が出来るようになった程度)ため、Apacheと連動させてみようと
試行錯誤を始めた状態です。
発生している問題・エラーメッセージ
[Sat Apr 01 23:18:58.424884 2023] [core:warn] [pid 11296:tid 408] AH00098: pid file C:/Apache24/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run? [Sat Apr 01 23:18:58.427033 2023] [mpm_winnt:notice] [pid 11296:tid 408] AH00455: Apache/2.4.56 (Win64) mod_wsgi/4.9.2 Python/3.11 configured -- resuming normal operations [Sat Apr 01 23:18:58.427033 2023] [mpm_winnt:notice] [pid 11296:tid 408] AH00456: Apache Lounge VS17 Server built: Mar 6 2023 10:53:37 [Sat Apr 01 23:18:58.427033 2023] [core:notice] [pid 11296:tid 408] AH00094: Command line: 'C:\\Apache24\\bin\\httpd.exe -d C:/Apache24' [Sat Apr 01 23:18:58.521944 2023] [mpm_winnt:notice] [pid 11296:tid 408] AH00418: Parent: Created child process 2456 [Sat Apr 01 23:18:59.913796 2023] [mpm_winnt:notice] [pid 2456:tid 412] AH00354: Child: Starting 64 worker threads. [Sat Apr 01 23:19:00.447126 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] mod_wsgi (pid=2456): Failed to exec Python script file 'C:/Apache24/flaskapps/yourapplication.wsgi'. [Sat Apr 01 23:19:00.447126 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] mod_wsgi (pid=2456): Exception occurred processing WSGI script 'C:/Apache24/flaskapps/yourapplication.wsgi'. [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] Traceback (most recent call last):\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] File "C:/Apache24/flaskapps/yourapplication.wsgi", line 3, in <module>\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] from app import app as application\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] File "C:\\Apache24/flaskapps\\app.py", line 1, in <module>\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] from flask import Flask\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] File "C:\\Users\\PCuser\\AppData\\Roaming\\Python\\Python311\\site-packages\\flask\\__init__.py", line 4, in <module>\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] from . import json as json\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] File "C:\\Users\\PCuser\\AppData\\Roaming\\Python\\Python311\\site-packages\\flask\\json\\__init__.py", line 8, in <module>\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] from ..globals import current_app\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] File "C:\\Users\\PCuser\\AppData\\Roaming\\Python\\Python311\\site-packages\\flask\\globals.py", line 4, in <module>\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] from werkzeug.local import LocalProxy\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] File "C:\\Users\\PCuser\\AppData\\Roaming\\Python\\Python311\\site-packages\\werkzeug\\__init__.py", line 1, in <module>\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] from .serving import run_simple as run_simple\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] File "C:\\Users\\PCuser\\AppData\\Roaming\\Python\\Python311\\site-packages\\werkzeug\\serving.py", line 17, in <module>\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] import socket\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] File "C:\\Program Files\\Python311\\Lib\\socket.py", line 51, in <module>\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] import _socket\r [Sat Apr 01 23:19:00.458004 2023] [wsgi:error] [pid 2456:tid 1340] [client ::1:51904] ModuleNotFoundError: No module named '_socket'\r [Sat Apr 01 23:19:00.972086 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] mod_wsgi (pid=2456): Failed to exec Python script file 'C:/Apache24/flaskapps/yourapplication.wsgi'., referer: http://localhost/ [Sat Apr 01 23:19:00.972086 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] mod_wsgi (pid=2456): Exception occurred processing WSGI script 'C:/Apache24/flaskapps/yourapplication.wsgi'., referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] Traceback (most recent call last):\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] File "C:/Apache24/flaskapps/yourapplication.wsgi", line 3, in <module>\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] from app import app as application\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] File "C:\\Apache24/flaskapps\\app.py", line 1, in <module>\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] from flask import Flask\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] File "C:\\Users\\PCuser\\AppData\\Roaming\\Python\\Python311\\site-packages\\flask\\__init__.py", line 4, in <module>\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] from . import json as json\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] File "C:\\Users\\PCuser\\AppData\\Roaming\\Python\\Python311\\site-packages\\flask\\json\\__init__.py", line 8, in <module>\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] from ..globals import current_app\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] File "C:\\Users\\PCuser\\AppData\\Roaming\\Python\\Python311\\site-packages\\flask\\globals.py", line 4, in <module>\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] from werkzeug.local import LocalProxy\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] File "C:\\Users\\PCuser\\AppData\\Roaming\\Python\\Python311\\site-packages\\werkzeug\\__init__.py", line 1, in <module>\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] from .serving import run_simple as run_simple\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] File "C:\\Users\\PCuser\\AppData\\Roaming\\Python\\Python311\\site-packages\\werkzeug\\serving.py", line 17, in <module>\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] import socket\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] File "C:\\Program Files\\Python311\\Lib\\socket.py", line 51, in <module>\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] import _socket\r, referer: http://localhost/ [Sat Apr 01 23:19:00.973273 2023] [wsgi:error] [pid 2456:tid 1336] [client ::1:51905] ModuleNotFoundError: No module named '_socket'\r, referer: http://localhost/
試したこと
まずは、調べてみた情報をそのままなぞって環境構築が正しく出来ていることを確認しようとしたところ、
Apacheを起動して、「http: //localhost/」へブラウザからアクセスしたら、上記エラーログがApacheのエラーログに
出力しています。
Pythonスクリプトの内容並びに手順は以下のURLの内容をそのままです。
https://qiita.com/NAKA_G/items/f34738df364af8cbd58e
※但し、Apacheのサービスインストールのみ行っていません。
経験が十分ではなく、試すべきことに気づいていない可能性もありますため、「こういうことを試した方がよい」などありましたら、
ご教示いただけますと幸いです。
補足情報(FW/ツールのバージョンなど)
Python:Python3.11
pipにてFlaskはじめ、単品での起動に必要な外部ライブラリは導入済み(単品起動後ブラウザから想定動作できることを確認済み)
Apache:httpd-2.4.56-win64-VS17
Flaskアプリ資材の置き場所
c:\Apache配下に「flaskapps」フォルダを作成し、上記URLで作成した「app.py」及び「wsgiファイル」を中に格納しています。
application.wsgi
1import sys 2sys.path.insert(0, 'C:/Apache24/flaskapps') 3from app import app as application
httpd.conf(追記部分)
1LoadFile "C:/Program Files/Python311/python311.dll" 2LoadModule wsgi_module "C:/Users/PCuser/AppData/Roaming/Python/Python311/site-packages/mod_wsgi/server/mod_wsgi.cp311-win_amd64.pyd" 3WSGIPythonHome "C:/Program Files/Python311" 4 5<VirtualHost *:80> 6 WSGIScriptAlias / "C:/Apache24/flaskapps/application.wsgi" 7 <Directory "C:/Apache24/flaskapps"> 8 Require all granted 9 </Directory> 10</VirtualHost> 11
app.py
1from flask import Flask 2 3# Flaskをappという変数で動かす宣言 4app = Flask(__name__) 5 6@app.route('/') 7def hello(): 8 name = "Flask Hello World" 9 return name 10 11# appの実行 12if __name__ == "__main__": 13 app.run()
単品で動作させた場合のログは以下の通りです。
* Serving Flask app 'app' * Debug mode: off WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on http://127.0.0.1:5000 Press CTRL+C to quit 127.0.0.1 - - [01/Apr/2023 23:39:41] "GET / HTTP/1.1" 200 - 127.0.0.1 - - [01/Apr/2023 23:39:41] "GET /favicon.ico HTTP/1.1" 404 -
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/05/04 14:34