Self-Host Evolution API on a VPS: Step-by-Step
In this article
This guide walks you through installing and running the Evolution API—a popular WhatsApp API wrapper—on your own VPS. By the end, you'll have a self-hosted instance that you control, which means no per-message fees, full data privacy, and the ability to customize the code. You'll need a VPS with at least 1 GB RAM, a domain name (or a subdomain), and basic comfort with the Linux command line.
What You'll Need
- A VPS running Ubuntu 22.04 or 24.04 (other Debian-based distros work too)
- A domain name pointing to your VPS's IP address (for HTTPS)
- SSH access to the VPS (root or a user with sudo privileges)
- Node.js 18 or 20 and npm installed
- Docker and Docker Compose (optional but recommended)
- A code editor and a way to transfer files (like VS Code with Remote SSH)
Step-by-Step
- Update your system. SSH into your VPS and run:
sudo apt update && sudo apt upgrade -y - Install Node.js and npm. If you don't have them, install via NodeSource:
Verify withcurl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt install -y nodejsnode -vandnpm -v. - Install Docker and Docker Compose (recommended). This makes the database and the API easier to manage:
sudo apt install -y docker.io docker-compose-v2 sudo systemctl enable --now docker - Clone the Evolution API repository. Use the official repo:
git clone https://github.com/EvolutionAPI/evolution-api.git cd evolution-api - Configure environment variables. Copy the example file and edit it:
Set at least these values:cp .env.example .env nano .envSERVER_URL– your public URL (e.g.,https://api.yourdomain.com)AUTHENTICATION_API_KEY– a strong random string (useopenssl rand -hex 32)DATABASE_ENABLED=trueandDATABASE_PROVIDER=postgresql(or keep SQLite for a quick test)DATABASE_CONNECTION_URI– if using Postgres, set the connection string
- Install dependencies and build. Run:
This may take a few minutes.npm install npm run build - Start the API with PM2 (or Docker). For PM2:
For Docker, use the providedsudo npm install -g pm2 pm2 start dist/src/main.js --name evolution-api pm2 save && pm2 startupdocker-compose.ymlafter editing it to match your.env. - Set up a reverse proxy with Nginx. Install Nginx, then create a config:
Add a server block that proxies tosudo apt install -y nginx sudo nano /etc/nginx/sites-available/evolutionhttp://localhost:8080(or your chosen port), including WebSocket support:
Enable it and restart Nginx.server { listen 80; server_name api.yourdomain.com; location / { proxy_pass http://localhost:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } } - Enable HTTPS with Certbot. Install and run:
Follow the prompts. Certbot will auto-renew.sudo apt install -y certbot python3-certbot-nginx sudo certbot --nginx -d api.yourdomain.com - Test the installation. Visit
https://api.yourdomain.com– you should see the API's welcome message. Then try creating an instance via the REST API using your API key.
Common Mistakes
- Forgetting to set
SERVER_URLcorrectly. If it's wrong, WebSocket connections fail and QR codes won't load. - Using a weak API key. Always generate a long random string; otherwise your instance is open to anyone.
- Not enabling WebSocket proxy headers. Without the
Upgradeheaders, real-time events won't work. - Running as root with PM2. Better to create a dedicated user, but if you must, at least secure the API key.
- Skipping the build step. Running
npm startwithout building will throw errors.
Tips
- Use a firewall (like UFW) to allow only ports 80, 443, and SSH.
- Set up automatic backups of your database (especially if you store chat history).
- Monitor logs with
pm2 logs evolution-apito catch issues early. - If you use Postgres, install
postgresql-clientand test the connection before starting the API. - Pin the version of the API you deploy to avoid unexpected breaking changes.
Troubleshooting
- API won't start. Check logs:
pm2 logs evolution-api. Common causes: missing env vars, wrong database URI, or port already in use. - QR code doesn't appear. Make sure your
SERVER_URLis exactly the same as your public URL (includinghttps://). Also check that the WebSocket proxy is configured. - Connection resets when sending messages. This usually means the WebSocket upgrade is not working. Recheck your Nginx config and restart Nginx.
- Database errors. If using Postgres, verify the connection string has the correct password and that the database exists. Try connecting manually with
psql. - Certbot fails. Ensure your domain resolves to your VPS IP and that port 80 is open. If you're behind a Cloudflare proxy, set DNS only (grey cloud) during issuance.
Frequently Asked Questions
Do I need a domain name?
Technically no, but you'll need it for HTTPS and to avoid mixed-content issues. You can use a free subdomain from services like DuckDNS.
Can I run this on a free tier VPS?
Yes, but be aware that the API uses about 300–500 MB RAM. A 512 MB VPS will be tight; 1 GB is comfortable.
How do I update to a newer version?
Pull the latest changes, reinstall dependencies, rebuild, and restart PM2. Always back up your database first.
Is it legal to use this API?
It depends on your use case and jurisdiction. You must comply with WhatsApp's Terms of Service and local privacy laws. This guide is technical only.
Can I use MySQL instead of Postgres?
Yes, Evolution API supports MySQL and MongoDB. Just change DATABASE_PROVIDER and the connection URI accordingly.
How do I secure my instance further?
Use a strong API key, restrict access by IP with Nginx, and enable HTTPS. Also consider running the API as a non-root user.