Environment construction of Flask / MySql / Apache / mod_wsgi / virtualenv with Redhat7 (Python2.7) November 2020

Verification environment

Installation and creation of application files

Install Apache / mod_wsgi


$ sudo su
$ yum install httpd
$ chkconfig httpd on
$ service httpd start
$ service httpd status #Confirmation
$ yum install mod_wsgi # mod_wsgi installation

pip installation


$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python get-pip.py

Install virtualenv


$ pip install virtualenv

Create application directory


$ mkdir /var/www/myapp
$ cd /var/www/myapp
$ virtualenv venv #Building a virtualenv environment
$ source venv/bin/activate #virtualenv enabled
$ pip install flask #installing flask
$ touch app.py #Create application file
$ touch app.wsgi #Create application file

app.py


from flask import Flask, jsonify

app = Flask(__name__)

@app.route("/")
def hello():
    return jsonify("Hello World!"), 201


if __name__ == "__main__":
    app.run()

app.wsgi


import os
import sys

DIR=os.path.dirname(__file__)
sys.path.append(DIR)
activate_this = os.path.join(DIR, 'venv/bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))

from app import app as application

The final file structure is as follows.

$ tree -L 2
.
├── app.py
├── app.wsgi
└── venv
    ├── bin
    ├── lib
    ├── lib64
    └── pyvenv.cfg

Apache / mod_wsgi settings

$ vi /etc/httpd/conf/httpd.conf

Add the following line

Listen 8888

When I add port 8888 and restart apache, I get the following error

(13)Permission denied: AH00072: make_sock: could not bind to address [::]:8888
(13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:8888

Add port with selinux Reference http://hetarena.com/archives/495

$ semanage port -a -t http_port_t -p tcp 8888

Build an environment for your application

$ vi /etc/httpd/conf.d/myenv.conf

myenv.conf


<VirtualHost *:8888>
    WSGIDaemonProcess wsgi_flask user=apache group=apache threads=10
    WSGIScriptAlias / /var/www/myapp/app.wsgi

    WSGIScriptReloading On

    <Directory "/var/www/myapp">
	WSGIProcessGroup wsgi_flask
	WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

--Check the configuration file

$ apachectl configtest

https://deep-blog.jp/engineer/12317/

$ service httpd graceful

Install mysql

$ sudo su
$ rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
$ yum install mysql-community-server
$ service mysqld start
$ service mysqld status #Confirmation

mysql login

$ sudo su
$ tail /var/log/mysqld.log #Check password from log
$ mysql -uroot
$ mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'YQM3rCyae8Ft?';

Reference https://dev.classmethod.jp/articles/how-to-serve-flask-with-apache-mod_wsgi-virtualenv-on-ec2/

Recommended Posts

Environment construction of Flask / MySql / Apache / mod_wsgi / virtualenv with Redhat7 (Python2.7) November 2020
Installation of Python3 and Flask [Environment construction summary]
Poetry-virtualenv environment construction with python of centos-sclo-rh ~ Notes
Manage python environment with virtualenv
Environment construction of python2 & 3 (OSX)
Environment construction of python and opencv
Get started with Python! ~ ① Environment construction ~
Build python virtual environment with virtualenv
Build Mysql + Python environment with docker
Environment construction of python3.8 on mac
Python3 environment construction with pyenv-virtualenv (CentOS 7.3)
pytorch @ python3.8 environment construction with pipenv
[Docker] Build an environment of python (Flask) + GraphQL (graphene) + MySQL (sqlalchemy)
Web application created with Python + Flask (using VScode) # 1-Virtual environment construction-
[Ubuntu 18.04] Python environment construction with pyenv + pipenv
Vue.js + Flask environment construction memorandum ~ with Anaconda3 ~
CentOS 6.4 with Python 2.7.3 with Apache with mod_wsgi and Django
Environment construction procedure: Ubuntu + Apache2 + Python + Pyramid
Clean python environment with pythonz and virtualenv
Let's get along with Python # 0 (Environment construction)
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Easy construction]
Automatic posting of web design gary site with python + selenium (1) Environment construction
Python3 TensorFlow environment construction (Mac and pyenv virtualenv)
Collecting information from Twitter with Python (Environment construction)
Prepare the execution environment of Python3 with Docker
Building a python environment with virtualenv and direnv
Python environment construction
Environment construction (python)
Manage Python multiple version environment with Pythonz, virtualenv
Use multiple versions of python environment with pyenv
python environment construction
python development environment -use of pyenv and virtualenv-
Python --Environment construction
Commands for creating a python3 environment with virtualenv
Work in a virtual environment with Python virtualenv.
Python local development environment construction template [Flask / Django / Jupyter with Docker + VS Code]
Python environment construction
First python ① Environment construction with pythonbrew & Hello World !!
From Python environment construction to virtual environment construction with anaconda
python environment construction
Until it works with virtualenv + flask + apache + wsgi
Recommendation of building a portable Python environment with conda
Build a python virtual environment with virtualenv and virtualenvwrapper
[Python] OpenCV environment construction with Docker (cv2.imshow () also works)
Data analysis environment construction with Python (IPython notebook + Pandas)
Web application made with Python3.4 + Django (Part.1 Environment construction)
Build a python virtual environment with virtualenv and virtualenvwrapper
Preparing the execution environment of PyTorch with Docker November 2019
QGIS3 Python plugin development environment construction with VSCode (macOS)
Unification of Python environment
python windows environment construction
homebrew python environment construction
Python development environment construction
Python environment with docker-compose
python2.7 development environment construction
Mac environment construction Python
Programming with Python Flask
Virtual environment with Python 3.6
Python environment construction @ Win7
Python environment construction on Mac (pyenv, virtualenv, anaconda, ipython notebook)
Unify the environment of the Python development team starting with Poetry