DEV Community

Rabeea Ali
Rabeea Ali

Posted on • Updated on

Deploy Soketi On Server

PART 1
PART 2
PART 3

In this post we will see how to deploy Soketi On AWS EC2. You can install it on whatever Hosting you have.

Prerequisites:

• Ready Fresh EC2 Instance

I used EC2 t2.micro

Now Connect With SSH And Let's Get Started 🚀

Step 1: prepare OS & Install The Tools

Update the server pkgs:

sudo yum update -y
Enter fullscreen mode Exit fullscreen mode

Install the required tools:

sudo yum install -y git python3 gcc build-essential
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Nodejs

Let's install node js & npm packages with these three commands

Please run one by one

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

. ~/.nvm/nvm.sh

nvm install --lts
Enter fullscreen mode Exit fullscreen mode

To Check the version of node run:

node -e "console.log('Running Node.js ' + process.version)"
Enter fullscreen mode Exit fullscreen mode

You should see Running Node.js: 1xxxx

Step 3: Install Soketi

Now let's install Soketi on the server with:

npm install -g @soketi/soketi
Enter fullscreen mode Exit fullscreen mode

Step 4: Keep The Soketi Server Alive

There are two ways to make Soketi alive by using Supervisor or PM2

For more information check the docs

I will choose PM2 & let's install it:

npm install -g pm2
Enter fullscreen mode Exit fullscreen mode

Now run Soketi using pm2:

pm2 start soketi -- start
Enter fullscreen mode Exit fullscreen mode

More commands might be useful for debugging Soketi:

pm2 status
pm2 monit
pm2 logs
Enter fullscreen mode Exit fullscreen mode

Step 5: Nginx

As we know Soketi using port 6001 by default and we need a way to make the server redirect to this port for anyone visiting the main domain, for that we need a web server that runs on port 80 and redirect to users to 6001, so Nginx(proxy) is prefect for this job.

Let's install Nginx:

sudo amazon-linux-extras install nginx1
Enter fullscreen mode Exit fullscreen mode

Then start the Nginx:

sudo systemctl start nginx.service
Enter fullscreen mode Exit fullscreen mode

Check the status of Nginx:

sudo systemctl status nginx.service 
Enter fullscreen mode Exit fullscreen mode

Now we need to Find the Nginx config file, you use command like nginx -t to give you the full path config file, or you probably find it in /etc/nginx/nginx.conf.

Let's open the config file with:

sudo vim /etc/nginx/nginx.conf
Enter fullscreen mode Exit fullscreen mode

Now add the proxy in nginx.conf inside server block:

server { 
   .......

    location / {
        proxy_pass             http://127.0.0.1:6001;
        proxy_read_timeout     60;
        proxy_connect_timeout  60;
        proxy_redirect         off;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
 }
Enter fullscreen mode Exit fullscreen mode

Save & Exit :wq :)

After adding the proxy, we need to restart the Nginx:

sudo systemctl restart nginx.service
Enter fullscreen mode Exit fullscreen mode

Now if you visit your public IP, you will see OK in the page, and that's mean you successfully redirect the server to Soketi port which is 6001. 🫡

After all, you now can use your public IP (without http://) in Laravel project by edit the .env with:

PUSHER_HOST=YOUR_PUBLIC_IP_HERE
PUSHER_PORT=80
Enter fullscreen mode Exit fullscreen mode

THAT'S FOR THIS PART

In part 3 we will see how to install SSL and change the configurations of Soketi.

👋

Top comments (2)

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
georgecavalcanti profile image
George Cavalcanti

Ok Rabeea, investigating a little more I found that the problem was in the httpclient gem that did not support accesses with lets encrypt ssl, I installed a branched version of github with this support and everything went well, thanks for the tutorial