Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Self-Host Evolution API on a VPS: Step-by-Step

· 4 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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

  1. Update your system. SSH into your VPS and run:
    sudo apt update && sudo apt upgrade -y
  2. Install Node.js and npm. If you don't have them, install via NodeSource:
    curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
    sudo apt install -y nodejs
    Verify with node -v and npm -v.
  3. 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
  4. Clone the Evolution API repository. Use the official repo:
    git clone https://github.com/EvolutionAPI/evolution-api.git
    cd evolution-api
  5. Configure environment variables. Copy the example file and edit it:
    cp .env.example .env
    nano .env
    Set at least these values:
    • SERVER_URL – your public URL (e.g., https://api.yourdomain.com)
    • AUTHENTICATION_API_KEY – a strong random string (use openssl rand -hex 32)
    • DATABASE_ENABLED=true and DATABASE_PROVIDER=postgresql (or keep SQLite for a quick test)
    • DATABASE_CONNECTION_URI – if using Postgres, set the connection string
  6. Install dependencies and build. Run:
    npm install
    npm run build
    This may take a few minutes.
  7. Start the API with PM2 (or Docker). For PM2:
    sudo npm install -g pm2
    pm2 start dist/src/main.js --name evolution-api
    pm2 save && pm2 startup
    For Docker, use the provided docker-compose.yml after editing it to match your .env.
  8. Set up a reverse proxy with Nginx. Install Nginx, then create a config:
    sudo apt install -y nginx
    sudo nano /etc/nginx/sites-available/evolution
    Add a server block that proxies to http://localhost:8080 (or your chosen port), including WebSocket support:
    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 it and restart Nginx.
  9. Enable HTTPS with Certbot. Install and run:
    sudo apt install -y certbot python3-certbot-nginx
    sudo certbot --nginx -d api.yourdomain.com
    Follow the prompts. Certbot will auto-renew.
  10. 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_URL correctly. 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 Upgrade headers, 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 start without 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-api to catch issues early.
  • If you use Postgres, install postgresql-client and 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_URL is exactly the same as your public URL (including https://). 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.