1. Install Apache # yum install -y httpd httpd-devel # systemctl start httpd.service # Start # systemctl stop httpd.service # Shutdown # systemctl restart httpd.service # Restart # systemctl enable httpd.service # Start automatically at boot Open port 80 on the firewall # firewall-cmd --zone=public --add-port=80/tcp --permanent # firewall-cmd --reload Open Apache, and the external network can access Apache's default page through IP 2. Install Python36, pip3, and virtualenv # yum install -y epel-release # yum install -y python36 # python36 -V Python 3.6.6 # yum install -y python36-setuptools # easy_install-3.6 pip # pip3 -V pip 18.1 from /usr/local/lib/python3.6/site-packages/pip-18.1-py3.6.egg/pip (python 3.6) # pip3 install virtualenv 3. Create a project Create a flask project (the simplest, a project folder, a 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 in 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 a virtual environment # yum install -y python36-devel.x86_64 # A dependency. If it is not installed, pip will report an error below. . # source py3env/bin/activate # Enter the virtual environment (py3env) # pip install mod_wsgi # Install mod_wsgi (py3env) # mod_wsgi-express install-module # Execute the command and 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 Apache configuration # vi /etc/httpd/conf/httpd.conf Copy the line obtained above and add it to the end of the configuration file Copy the code 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 (according to: https://dormousehole.readthedocs.io/en/latest/deploying/mod_wsgi.html) 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 sys sys.path.insert(0, '/var/www/flask_test') from app import app as application Configure Apache # vi /etc/httpd/conf/httpd.conf Write the following (according to: https://dormousehole.readthedocs.io/en/latest/deploying/mod_wsgi.html#id1) <VirtualHost *:80> ServerName example.com WSGIScriptAlias / /var/www/flask_test/app.wsgi <Directory /var/www/flask_test> Require all granted </Directory> </VirtualHost> OK, start Apache, and you can access the web page through the IP of this server Test some two paths written in app.py The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed example of MySQL exchange partition
>>: MySQL deduplication methods
Use CSS filter to write mouse over effect <div...
Table of contents Preface 1. Linux changes the yu...
0. Background Hardware: Xiaomi Notebook Air 13/In...
In most application scenarios, we need to back up...
This article example shares the specific code of ...
Table of contents 1. Delete the old version 2. Ch...
Table of contents Update the image from an existi...
Introduction to Linux alarm function Above code: ...
Description of port availability detection when p...
This article uses an example to illustrate the co...
Table of contents background Inspiration comes fr...
The blogger hasn't used MySQL for a month or ...
Table of contents 1. Process 2. Core Architecture...
HTML reuse is a term that is rarely mentioned. Tod...
Table of contents The basic concept of modularity...