Creating LAMP WebSocket server with Rachet

We will be working in a LAMP server in DigitalOcean with a URL. Proceed only if you know how to access your files via ssh and sftp.


First, get SSL in your server.


SSH into your droplet/server and run the following command:

sudo a2enmod proxy_http


Download https://github.com/gabrielfs7/ratchet-chat and extract it into your var/www folder such that chat-server.php is located in var/www/bin/chat-server.php.


Edit your var/www/bin/chat-server.php file such that we use port 8000 (not the default 8080). If you decide to skip this make sure to replace the next steps with the new port number (xxxx instead of 8000).


Edit your /var/www/html/index.php file such that the connection is:

var conn = new WebSocket('wss://yourdomain.com/wss2/');


In your server, open your /etc/apache2/sites-available/000-default-le-ssl.conf file and add ProxyPass /wss2/ ws://yourdomain.com:8000:

<VirtualHost *:443>
...
        ProxyPass /wss2/ ws://yourdomain.com:8000
...
</VirtualHost>


To get the https based load balancer working, run the following commands:

sudo a2enmod ssl
sudo a2enmod proxy
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http
sudo a2enmod proxy_wstunnel

Comments (0)

Search Here