Here's a quick run-thru of how to upload project zip files for flask apps which you've created on a local machine, to a Linux VPS:
On your VPS server, create a new tmux session & python environment:
tmux new -s myapp
python3 -m venv myapp
cd myapp
source bin/activate
On your local computer, send your project file to the server:
scp -P7822 myapp.zip username@yourserverdomain:~/myapp
(select 'yes' if prompted to save a fingerprint the 1st time you SCP to a server)
enter your password when prompted
(BTW, I keep text files available with these upload commands and the password for each project/server, in each project zip file.)
On your VPS server, in the folder created above: unzip, edit and run your app:
ls
unzip -o myapp.zip
# if your project code is contained in a subfolder in the zip file:
cd myappfolder
# install all the python libraries required to run your app (only needed once per environment)
pip install -r requirements.txt
# edit: host='0.0.0.0', port=9999 (default is 5000 for flask) in app.run():
nano app.py
# allow the port above in your firewall, if you have ufw installed:
ufw allow 5000
# the file which starts your app is usually app.py or run.py
python3 app.py
# To stop a running flask app, within a tmux session:
CTRL C
# To detach your current tmux session
CTRL B
# To re-attach an existing tmux session:
tmux a -t myapp
If you want to set up https and subdomains with caddy:
tmux a -t caddy # if you're running caddy in a session
nano /etc/caddy/Caddyfile
add a section as follows, for each app port:
yoursubdomain.yourserverdomain.com {
reverse_proxy localhost:5000
}
Then reload caddy:
sudo systemctl reload caddy
# or, if you're running caddy in a docker container:
# sudo docker exec caddy caddy reload --config /etc/caddy/Caddyfile
To get a local app packaged as a zip file, ready to install using the steps above, a prompt for Pi may be something like:
There is currently a flask app running at http://127.0.0.1:5006/ on this machine. Please provide a zip file with all the code, config settings, and everything else required to install this application on another server.
If you've built the app on one VPS and want to prepare to move it to another server, add this following line to the prompt:
Please serve this zip file over http (ensure the port is open in ufw).