Laravel-Echo-Server installation on Forge with SSL Enabled with the Redis broadcast driver and Socket.io
Install echo server globally through npm install -g laravel-echo-server
Navigate to project root then run laravel-echo-server init
Do you want to run this server in development mode? No
Which port would you like to serve from? 6001
Which database would you like to use to store presence channel members? redis
Enter the host of your Laravel authentication server. https://project-domain.com
Will you be serving on http or https? https
Enter the path to your SSL cert file. /etc/nginx/ssl/project-domain.com/XXXXXX/server.crt
Enter the path to your SSL key file. /etc/nginx/ssl/project-domain.com/244397/server.key
(You can get these from Forge by navigating to your Site and selecting Edit Files > Edit Nginx Configuration)
Do you want to generate a client ID/Key for HTTP API? Yes
Take note of the Client ID and Key that is displayed. If not, you can always reference them in the laravel-echo-server.json
Now open up laravel-echo-server.json in the project root, and change the redis databaseConfig to the following:
"redis": {
"port": "6379",
"host": “project-domain.com”
},
"sqlite": {}
Now update your .env with the Client ID and Key
PUSHER_APP_ID=client_id
PUSHER_KEY=client_key
PUSHER_SECRET=null
Remember to run php artisan config:cache
if you have cached configuration that needs to be reloaded.
You will now need to update resources/assets/js/bootstrap.js as follows. Take note of the namespace parameter, which will affect the socket listens for Laravel Events.
window.Echo = new Echo({
namespace: ‘App\\Events',
broadcaster: 'socket.io’,
host: 'project-domain.com:6001'
});
Now you can update your view to include the following. I placed it in the HTML head:
<script src="https://project-domain.com:6001/socket.io/socket.io.js"></script>
We now need to open the ports to allow socket.io and redis to work. In Forge under Server Details click on Network.
I used the following settings here: Name: SOCKETIO Port: 6001
Name: REDIS Port: 6379
I left the from IP field blank in both cases because I am not sure how to restrict the IP to just the localhost. I tried 127.0.0.1 but it didn’t work.
Test the echo server by running laravel-echo-server start
from the project root.
You should now see
Starting server...
✔ Running at localhost on port 6001
✔ Channels are ready.
✔ Listening for http events...
✔ Listening for redis events...
Server ready!
It is important that the http events and redis events are ticked. Now stop the laravel-echo-server.
The final step that remains is to start up laravel-echo-server as a daemon process. This will ensure that Supervisor will keep the process running at all times. In Forge under Server Details now click on Daemons.
Use the following settings here:
Command: /usr/bin/laravel-echo-server start
User: forge
Directory: /home/forge/your-domain.com
Everything else you need to know is included in Taylor’s Laracasts on Echo 🙂
https://laracasts.com/lessons/introducing-laravel-echo
Good luck!