Evolution API can be easily installed using the Node Version Manager (NVM). Follow these steps to set up your environment and start the Evolution API on your server.

Install NVM

First, download and install Node.js. You can do this by running the following commands:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

Now, just point to the NVM directories and install Node:

Terminal
# Load bash source into the environment
source ~/.bashrc

# Directories
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

# Install node:
nvm install v20.10.0 && nvm use v20.10.0

Confirm that NVM was successfully installed:

command -v nvm

If you haven’t configured it yet, you can also set up your private server’s timezone with the following command:

dpkg-reconfigure tzdata

Clone the official GitHub repository to your private server.

git clone https://github.com/EvolutionAPI/evolution-api.git

Next, navigate to the folder where the project is located.

cd evolution-api
npm install

Now, let’s copy the env.yml file with the settings you need to edit.

cp src/dev-env.yml src/env.yml
nano src/env.yml

This command creates a copy of the default environment file.

Next, open the env.yml file in a text editor to enter your configuration settings. You can use nano, a command-line text editor, for this purpose:

nano src/env.yml

In the nano editor, navigate through the file and replace the default values with your specific settings. This can include database connection strings, API keys, server ports, etc.

Refer to the environment variables section for detailed instructions on how to set up your env.yml file.

To start the Evolution API, use the following command:

npm run build
npm run start:prod

Install and Configure PM2

Use PM2 to install PM2 and start the manager for the API process:

Terminal
npm install pm2 -g
pm2 start 'npm run start:prod' --name ApiEvolution
pm2 startup
pm2 save --force

Optional: You may need to allocate more memory for PM2, especially if your server has the capacity:

pm2 start 'npm run start:prod' --name ApiEvolution -- start --node-args="--max-old-space-size=4096" --max-memory-restart 4G

In the example above, it is assumed that your VPS has at least 4GB of RAM available exclusively for the Evolution API.

Available memory may vary, we recommend at least 1GB to run Evolution.

If you want to ensure the API is running, simply use your browser to access http://localhost:8080. This should be the response from your browser:

http://localhost:8080/
{
    "status": 200,
    "message": "Welcome to Evolution API, it is working!",
    "version": "1.x.x",
    "documentation": "http://localhost:8080/docs"
}

Make your life easier with the JSON Formatter extension in Google Chrome or Microsoft Edge.

EvolutionAPI has built-in Swagger endpoint documentation, which you can use to see all possible endpoints and test requests by accessing http://localhost:8080/docs.

Nginx Configuration

First, let’s install, start, enable, and test the Nginx service on your private server.

Terminal
apt-get install -y nginx
systemctl start nginx
systemctl enable nginx
systemctl status nginx

If the information “Active: active (running)” appears in green, it means that Nginx is running and you can proceed to the next step.

Remove Default Nginx Configuration

First, remove the default site file that comes enabled with Nginx:

rm /etc/nginx/sites-enabled/default

Create a new server block file in the directory

nano /etc/nginx/conf.d/default.conf

Next, paste the Nginx configuration into the default.conf file:

/etc/nginx/conf.d/default.conf
server {
  listen 80;
  listen [::]:80;
  server_name _;
  root /var/www/html/;
  index index.php index.html index.htm index.nginx-debian.html;

location / {
    try_files $uri $uri/ /index.php;
  }

location ~ \.php$ {
    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
  }

# Long browser cache time can speed up repeat visits to your page
location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
       access_log off;
       log_not_found off;
       expires 360d;
  }

# disable access to hidden files
location ~ /\.ht {
      access_log off;
      log_not_found off;
      deny all;
  }
}

After making changes to the Nginx settings, it is essential to reload the Nginx service. This ensures that any modifications you have made are applied and become effective.

Run the following command in the terminal to reload Nginx:

systemctl reload nginx

Make the nginx user the owner of the web directory, by default, it is owned by the root user:

chown www-data:www-data /usr/share/nginx/html -R

Now, create a Virtual Host pointing to your subdomain by editing the api file:

cd ~
nano /etc/nginx/sites-available/api

Next, paste the Nginx configuration into the api file:

/etc/nginx/sites-available/api
server {
  server_name replace-this-with-your-cool-domain.com;

location / {
    proxy_pass http://127.0.0.1:8080;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_cache_bypass $http_upgrade;
  }
}

Create a symbolic link between the api and sites-enabled files:

ln -s /etc/nginx/sites-available/api /etc/nginx/sites-enabled

Next, validate the Nginx configuration for the subdomain:

nginx -t

This message should appear on your terminal if everything has been set up correctly: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

Reload Nginx for the changes to take effect.

systemctl reload nginx

Install Certbot for SSL Certificate

To secure your Evolution API with an SSL certificate, you can use Certbot. Install Certbot using the following command:

snap install --classic certbot

Certify the API subdomain

certbot --nginx -d replace-this-with-your-cool-domain.com

You will be asked if you want to enter an email to receive notifications when the generated certificate is close to its expiration date.

If the certification is successful, at the end of the process, a line with the following message will be displayed:

“Congratulations! You have successfully enabled HTTPS”