This guide explains the steps for deploying a Streamlit application on an Ubuntu-based Hostinger VPS using Systemd for persistence, Poetry for dependency management, and Nginx for secure web access (HTTPS).
This phase establishes the foundational environment and prepares your code.
Action: Log in via SSH and install the necessary system packages and the Poetry package manager.
ssh root@your_vps_ip
sudo apt update && sudo apt upgrade -y
sudo apt install python3 python3-pip git nginx curl -y
curl -sSL <https://install.python-poetry.org> | python3 -
Explanation: We install Python, Git, and Nginx (web server) and Poetry (dependency management) to ensure the environment is ready to host the app.
Action: Clone your repository and use Poetry to create the virtual environment and install dependencies.
cd /root/
git clone <https://github.com/egorhowell/Prophet-Forecasting-For-Portfolio-Optimisation>
cd Prophet-Forecasting-For-Portfolio-Optimisation
poetry install
Explanation: Poetry isolates your app's libraries, preventing version conflicts with other software on the VPS.
.env)Action: Create the essential .env file in the project root and insert your Supabase credentials.
# Ensure this command captures the correct variables from your shell
echo "SUPABASE_URL=\\"$SUPABASE_URL\\"" > .env
echo "SUPABASE_KEY=\\"$SUPABASE_KEY\\"" >> .env
Explanation: The Systemd service cannot read the personal .bashrc file. This dedicated .env file is securely loaded by Systemd to inject secrets into the application environment.
This phase ensures the app runs 24/7 in the background and restarts automatically if it fails.
Action: Create the service file /etc/systemd/system/streamlit-app.service and populate it. **(Replace the ExecStart path with the output from Step 4).**BashIni, TOML
sudo nano /etc/systemd/system/streamlit-app.service
[Unit]
Description=Streamlit App Service
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/root/Prophet-Forecasting-For-Portfolio-Optimisation
EnvironmentFile=/root/Prophet-Forecasting-For-Portfolio-Optimisation/.env
# REPLACE THE PATH BELOW:
ExecStart=/path/to/poetry/venv/bin/python -m streamlit run src/streamlit_app.py --server.port 8501 --server.address 0.0.0.0
Restart=always
[Install]
WantedBy=multi-user.target
Explanation: EnvironmentFile loads the credentials. Restart=always guarantees the app restarts automatically. The ExecStart command runs Streamlit on the internal port 8501.
Action: Reload Systemd, enable auto-start, and launch the service.
sudo systemctl daemon-reload
sudo systemctl enable streamlit-app.service # Enables auto-start on boot
sudo systemctl start streamlit-app.service
sudo systemctl status streamlit-app.service
Explanation: The service is now managing the app, ensuring it runs persistently in the background.