$ sudo su
$ yum install httpd
$ chkconfig httpd on
$ service httpd start
$ service httpd status #Confirmation
$ yum install mod_wsgi # mod_wsgi installation
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python get-pip.py
$ pip install virtualenv
$ 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
$ 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
$ 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
$ 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
$ 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