When creating and publishing a simple application using Python, the web server is Apache, and the web application framework is [flask](https://flask.palletsprojects. I think the combination of com / en / 1.1.x /) is common. And WSGI (Web Server Gateway Interface) that connects Apache and flask will use mod_wsgi.
Create an instance of EC2 on AWS, install Apache, and run the app written in flask! I also installed mod_wsgi so it should work fine! I was thinking, but sometimes I get the following error:
mod_wsgi (pid=8711): Target WSGI script '/var/www/xxx/xxx.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=8711): Exception occurred processing WSGI script '/var/www/xxx/xxx.wsgi'.
Why did you install mod_wsgi? However, the conclusion is that mod_wsgi installed by yum install mod_wsgi
is old and only compatible with Python 2 series (in the case of Cent OS series OS).
So if you installed mod_wsgi with yum install mod_wsgi
, you need to uninstall it with yum remove mod_wsgi
. After that, if you install via pip like pip install mod_wsgi
, you can install mod_wsgi corresponding to Python3 series.
For example, if you are using venv
to create a Python 3.7 virtual environment, running the above pip command will
$VENVHOME/lib/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so
A shared library file for mod_wsgi will be created in this location. Then, if you write the following in the Apache conf file, mod_wsgi corresponding to Python3 will be executed.
LoadModule wsgi_module $VENVHOME/lib/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so
Congratulations, congratulations. Even so, there are many pitfalls with the Python version ...
Recommended Posts