This is an old revision of the document!
Using Python in Development Mode
It involves two aspects - launching the app from SSH console, and then linking to the the VHost/Website URL end point. Lets go step by step on it.
Step 1 : Log into N99panel. From under N99panel dashboard, click 'List Users'
Step 2 : You will see the list of all the users. Please click 'Manage SSHD/CronD' link against the appropriate user
Step 3 : Now choose 'Full SSHD mode with Python'. With this you get the maximum command set which includes python3 and pip3 binaries along with git and other useful command set.
When you click 'Submit', upon successful job execution, the SSHD daemon would restart, and its host signature would change from what it was earlier. This implies that when you try to connect via SSH, you will get a warning for the same, and that you need to appropriately handle at your end.
Step 4 : SSH using to the VPS using the above user's credentials
Step 5 : Change over to directory/folder python_apps . If it is not created, please create it manually. python_apps folder is also used when you have to later launch your app in production mode
Assuming you are /home/user folder, please run the below command to create python_apps folder, if it does not exist.
mkdir python_apps
Now change into python_apps folder
cd python_apps
Step 6 : From within this folder add/create your python project as you would normally do. Below we illustrate with specific examples for Flask, Django and Generic modes
Flask
mkdir flask-project cd flask-project python3 -m venv .venv source .venv/bin/activate
Running the last command with activate the virtual environment, proceeding further
pip install flask pip install gunicorn
You you can upload/write your Flask app and fire it up using gunicorn, but here I will showcase an example using the hello world app - refer https://flask.palletsprojects.com/en/2.3.x/quickstart/
Below code is saved to hello.py
from flask import Flask app = Flask(__name__) @app.route("/") def hello_world(): return "<p>Hello, World!</p>"
Now to fire our flash app, we use gunicorn
gunicorn -b 0.0.0.0:8000 -w 4 --forwarded-allow-ips='172.16.26.1' hello:app
To run it in background, we append & to the above command
gunicorn -b 0.0.0.0:8000 -w 4 --forwarded-allow-ips='172.16.26.1' hello:app &
To exit virtual environment use the command
deactivate
Django
mkdir django-project cd django-project python3 -m venv .venv source .venv/bin/activate
Running the last command with activate the virtual environment, proceeding further
pip install flask pip install gunicorn
You you can upload/write your Flask app and fire it up using gunicorn, but here I will showcase an example using the hello world app - refer https://flask.palletsprojects.com/en/2.3.x/quickstart/
Below code is saved to hello.py
from flask import Flask app = Flask(__name__) @app.route("/") def hello_world(): return "<p>Hello, World!</p>"
Now to fire our flash app, we use gunicorn
gunicorn -b 0.0.0.0:8000 -w 4 --forwarded-allow-ips='172.16.26.1' hello:app
To run it in background, we append & to the above command
To exit virtual environment use the command
deactivate
gunicorn -b 0.0.0.0:8000 -w 4 --forwarded-allow-ips='172.16.26.1' hello:app &