Tuesday, April 4, 2023

How To Install Flask with Gunicorn and Nginx on Oracle Linux 9

 in This Tutorial you will Learn " How To Install Flask with Gunicorn and Nginx on Oracle Linux 9"
Flask is a web application framework written in Python.
Gunicorn is a WSGI server.
NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more.
__________________________________________________________________________________________________________________________________
Server - Os:  Oracle Linux Server 9.0   64Bit      | IP -192.168.1.50        |Hostname - server.testbox.com
__________________________________________________________________________________________________________________________________
cat /etc/system-release ; hostname ; hostname -I ; dnf groupinstall "Development Tools" -y
sudo dnf update ;  sudo dnf install epel-release -y
sudo dnf install python3-pip python3-devel gcc -y
dnf install nginx -y
nginx -version


dnf install --assumeyes python3-pip
pip3 install virtualenv
sudo update-crypto-policies --set LEGACY
sudo reboot
sudo mkdir /sample_project && cd /sample_project
sudo chmod 777 /sample_project
virtualenv projectenv
source projectenv/bin/activate

pip3 install gunicorn flask
pip install --upgrade pip
nano  /sample_project/helloworld.py
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return "<h1 style='color:red'>Hello, World!</h1>"

if __name__ == '__main__':
    app.run(host='0.0.0.0')


sudo firewall-cmd --add-port=5000/tcp --permanent ; sudo firewall-cmd --reload

python helloworld.py
http://127.0.0.1:5000


nano /sample_project/wsgi.py
from helloworld import app

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

firewall-cmd --add-port=8000/tcp --permanent ; firewall-cmd --reload
python helloworld.py
http://0.0.0.0:8000
deactivate
gunicorn --bind 0.0.0.0:8000 wsgi:app
_________________________________________________________________________________________________________________________________

No comments:

Post a Comment