In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, the editor will share with you the relevant knowledge points about how CentOS7 deploys Flask. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
First, install apache
# yum install-y httpd httpd-devel# systemctl start httpd.service # Startup # systemctl stop httpd.service # shutdown # systemctl restart httpd.service # restart # systemctl enable httpd.service # Boot
Firewall opens port 80
# firewall-cmd-zone=public-add-port=80/tcp-permanent# firewall-cmd-reload
Enable apache, and the public network can already access the default page of apache through ip.
Second, install python36, pip3, virtualenv
# yum install- y epel-release# yum install- y python36# python36- vpython 3.6.The yum install- y python36-setuptools# easy_install-3.6 pip# pip3-vpip 18.1 from / usr/local/lib/python3.6/site-packages/pip-18.1-py3.6.egg/pip (python3.6) # pip3 install virtualenv
Third, create a project
Create a flask project (at its simplest, one project folder, one startup file)
# mkdir / var/www/flask_test # Project folder # vi / var/www/flask_test/app.py # Startup File
Example of startup file:
From flask import flask, request app = flask (_ _ name__) @ app.route ('/') def hello_world (): return 'hello world' @ app.route (' / hello') def hello (): name = request.args.get ('name','') return' hello' + name +'!' If _ _ name__ = ='_ _ main__': app.run ()
Create a virtual environment under the project folder and install flask
# cd / var/www/flask_test# virtualenv py3env # create a virtual environment # source py3env/bin/activate # enter the virtual environment (py3env) # pip install flask # install flask (py3env) # deactivate # exit the virtual environment
4. Install mod_wsgi with pip in virtual environment
# yum install-y python36-devel.x86_64 # A dependency. If not installed, the following pip will report an error. # source py3env/bin/activate # enter the virtual environment (py3env) # pip install mod_wsgi # install mod_wsgi (py3env) # mod_wsgi-express install-module # execute this command Copy the output loadmodule wsgi_module "/ usr/lib64/httpd/modules/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so" wsgipythonhome "/ var/www/flask_test/py3env" (py3env) # deactivate # exit the virtual environment
Modify the configuration of apache
# vi / etc/httpd/conf/httpd.conf
Copy the line above and add it to the end of the configuration file
The copy code is as follows:
Loadmodule wsgi_module "/ usr/lib64/httpd/modules/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
5. Configure mod_wsgi
# vi / var/www/html/flask_test/app.wsgi
Write the following (based on:)
Activate_this ='/ var/www/flask_test/py3env/bin/activate_this.py'with open (activate_this) as file_: exec (file_.read (), dict (_ _ file__=activate_this)) import syssys.path.insert (0,'/ var/www/flask_test') from app import app as application
Configure apache
# vi / etc/httpd/conf/httpd.conf
Write the following (based on:)
Servername example.com wsgiscriptalias / / var/www/flask_test/app.wsgi require all granted
Ok, start apache, and you can access the web page through the ip of this server
Test the two paths written in some app.py
These are all the contents of the article "how CentOS7 deploys Flask". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.