DEV Community

Rabeea Ali
Rabeea Ali

Posted on • Updated on

Install SSL On Server With Soketi

PART 1
PART 2
PART 3

In this part we will see how to configure Soketi and how to install SSL certificate.

Step 1: Change the default config of Soketi

This step is optional

As we know the default credentials of Soketi is:

  • App ID: app-id
  • App Key: app-key
  • Secret: app-secret

To change these credentials first we need to create a folder.

sudo mkdir /etc/my_soketi
Enter fullscreen mode Exit fullscreen mode

Enter the folder (change the folder/file name as you want)

cd /etc/my_soketi
Enter fullscreen mode Exit fullscreen mode

Create a json file config.json

sudo vim config.json
Enter fullscreen mode Exit fullscreen mode

Contains:

{
  "debug": true,
  "port": 6001,
  "appManager.array.apps": [
    {
      "id": "your-new-id",
      "key": "your-new-key",
      "secret": "your-new-secret"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

If you want to see the logs of Soketi make "debug": true,, and if you do not care just make false.

Now we need to turn off our Soketi server running by pm2:

pm2 stop soketi
Enter fullscreen mode Exit fullscreen mode

If you need to know the name run pm2 status and take the name of service

And now rerun the Soketi server by:

pm2 start soketi -- start --config=/etc/my_soketi/config.json
Enter fullscreen mode Exit fullscreen mode

Now change the credentials in Laravel project in .env file to the new one.

Step 2: Link IP With Domain

Go to the domain provider and make a new subdomain(domain) and create a new record then put your public IP.

After you make sure that the subdomain is run your Soketi server by returning OK when you open the domain, go to Nginx config file and update the server_name to your subdomain.

sudo vim /etc/nginx/nginx.conf

server_name  your_subodmain;
Enter fullscreen mode Exit fullscreen mode

Now restart the Nginx

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

Step 3: Install SSL

I will use let's encrypt to install SSL on my domain.

To install SSL run these three commands:

sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

sudo yum-config-manager --enable epel

sudo yum install certbot python2-certbot-nginx -y
Enter fullscreen mode Exit fullscreen mode

Then run:

sudo certbot --nginx
Enter fullscreen mode Exit fullscreen mode

Some questions will show:

1. type your email: XXXXXX@gmail.com
2. (Y)es/(N)o: y
3. (Y)es/(N)o: y
4. 
blank to select all options shown (Enter 'c' to cancel): 1
Enter fullscreen mode Exit fullscreen mode

Now you will get your SSL on domain once you visit it.

To renew the Certificate automatically you need to set a cronjob via crontab. The commands are given below.

sudo crontab -e
Enter fullscreen mode Exit fullscreen mode

put this line into the file:

0 3 * * * sudo certbot renew >/dev/null 2>&1
Enter fullscreen mode Exit fullscreen mode

Step 4: Configure The Laravel App With SSL.

in .env:

PUSHER_APP_KEY=key
PUSHER_APP_ID=id
PUSHER_APP_SECRET=secret
PUSHER_HOST="sub.app.co"
PUSHER_PORT=443
PUSHER_SCHEME=https

VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
Enter fullscreen mode Exit fullscreen mode

In bootstrap.js:

window.Echo = new Echo({
    broadcaster: "pusher",
    key: import.meta.env.VITE_PUSHER_APP_KEY,
    forceTLS: false,
    encrypted: import.meta.env.VITE_PUSHER_ENCRYPTED === "true",
    wsHost: import.meta.env.VITE_PUSHER_HOST,
    wsPort: import.meta.env.VITE_PUSHER_PORT,
    wssPort: import.meta.env.VITE_PUSHER_PORT,
    disableStats: true,
    enabledTransports: ["ws", "wss"],
});
Enter fullscreen mode Exit fullscreen mode

That's it 🚀

I would thank @Sinnbeck on laracast.com that helping me to finish this series ❤️

Top comments (0)