Deploy Soketi On Server
Tags: laravel, soketi, ec2
Published: 2022-08-26 14:48:38

---
title: Deploy Soketi On Server
published: true
description: This is the part two of how to use Soketi with Laravel 
tags: laravel, soketi, ec2
---
[PART 1](https://dev.to/rabeeaali/how-to-use-soketi-with-laravel-pt1-47hd)
[PART 2](https://dev.to/rabeeaali/deploy-soketi-on-aws-ec2-28e6)
[PART 3](https://dev.to/rabeeaali/install-ssl-on-server-with-soketi-45bn)

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
```

Install the required tools:

```
sudo yum install -y git python3 gcc build-essential
```

### 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
```

To Check the version of node run:
```
node -e "console.log('Running Node.js ' + process.version)"
```
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
```

### 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](https://docs.soketi.app/getting-started/installation/cli-installation#supervisor)

I will choose PM2 & let's install it:

```
npm install -g pm2
```

Now run Soketi using `pm2`:

```
pm2 start soketi -- start
```

More commands might be useful for debugging `Soketi`:

```
pm2 status
pm2 monit
pm2 logs
```

### 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
```

Then start the Nginx:
```
sudo systemctl start nginx.service
```

Check the status of Nginx:
```
sudo systemctl status nginx.service 
```

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
```

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;
    }
 }
```
Save & Exit `:wq` :)

After adding the proxy, we need to restart the Nginx:
```
sudo systemctl restart nginx.service
```

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
```

THAT'S FOR THIS PART

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

👋