How to host a Telegram bot on a VPS
A Telegram bot on your laptop dies when the lid closes. On a VPS it runs day and night, reconnects after a reboot, and restarts itself if it crashes. This is the minimum viable production deploy — Python, a virtualenv and a systemd service — done properly.
What a bot actually needs
Almost nothing. A polling Telegram bot opens an outbound connection to Telegram and waits for updates — no inbound ports, tiny RAM, negligible bandwidth. The entire value of a VPS here is uptime: a stable place that is always on. That is why a $4 plan is plenty, and why the focus below is on keeping the process alive, not on horsepower.
Prerequisites
- A bot token from @BotFather.
- An Ubuntu VPS with a
deployuser — do initial server setup first. Tested on a $3.49 Inferno VPS.
Step 1 — Python and a virtualenv
sudo apt update
sudo apt install -y python3 python3-venv python3-pip
mkdir ~/mybot && cd ~/mybot
python3 -m venv venv
source venv/bin/activate
pip install python-telegram-bot
Step 2 — A minimal bot
nano bot.py
import os, logging
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes
logging.basicConfig(level=logging.INFO)
async def start(update: Update, ctx: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("Hello from a VPS that never sleeps.")
def main():
token = os.environ["BOT_TOKEN"]
app = Application.builder().token(token).build()
app.add_handler(CommandHandler("start", start))
app.run_polling()
if __name__ == "__main__":
main()
Note the token comes from an environment variable — never hard-code it in the file.
Step 3 — The environment file
nano ~/mybot/.env
BOT_TOKEN=123456:your-token-from-botfather
chmod 600 ~/mybot/.env
Step 4 — A systemd service
This is what makes it production. systemd starts the bot on boot and restarts it if it dies:
sudo nano /etc/systemd/system/mybot.service
[Unit]
Description=My Telegram bot
After=network-online.target
Wants=network-online.target
[Service]
User=deploy
WorkingDirectory=/home/deploy/mybot
EnvironmentFile=/home/deploy/mybot/.env
ExecStart=/home/deploy/mybot/venv/bin/python bot.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now mybot
sudo systemctl status mybot
Message your bot /start — it should reply. Restart=always means a crash brings it right back. The deeper systemd walkthrough (graceful shutdown, journald tips) is in Python bot + systemd.
Step 5 — Read the logs
journalctl -u mybot -f # live
journalctl -u mybot --since "1 hour ago"
All your bot's stdout goes to journald automatically — no log files to rotate.
Polling vs webhook
This guide uses long polling, which needs no domain, no SSL and no open ports — ideal to start. If your bot grows or you want lower latency, read webhook vs long polling. For a Node.js bot instead, see Node.js + PM2.
A cheap always-on home for your bot
A Telegram bot barely touches resources — the $3.49 Inferno plan is more than enough, with eight EU + Asia locations and 24/7 uptime.
What to do next
- Python bot + systemd — the robust production unit.
- Webhook vs polling — pick the right mode.
- Best VPS for a Telegram bot — sizing and picks.
Author: Daniel Ferro — Self-hosting writer, Lisbon. Last tested: 2026-05-20 on python-telegram-bot 21, Python 3.11, Ubuntu 22.04.