{"id":1023,"date":"2025-06-03T09:15:40","date_gmt":"2025-06-03T09:15:40","guid":{"rendered":"https:\/\/www.ystsol.com\/blog\/?p=1023"},"modified":"2025-06-03T09:16:05","modified_gmt":"2025-06-03T09:16:05","slug":"deploying-laravel-reverb-to-production","status":"publish","type":"post","link":"https:\/\/www.ystsol.com\/blog\/deploying-laravel-reverb-to-production\/","title":{"rendered":"Deploying Laravel Reverb to Production"},"content":{"rendered":"\n<p><strong>Quick Information:&nbsp;<\/strong>This post assumes that your core Laravel application is already working, has reverb package already installed and being served on a domain. We will configure Nginx, create a systemd service to start Reverb, and set the correct environment variables to ensure Reverb works properly.<\/p>\n\n\n\n<p>So you&#8217;ve built that amazing real-time chat feature with Laravel Reverb, and it&#8217;s working beautifully on your local machine. Users are connecting, messages are flying back and forth, and everything feels snappy and responsive. But now comes the moment every developer dreads:&nbsp;<strong>deploying WebSockets to production<\/strong>.<\/p>\n\n\n\n<p>I&#8217;ve been there. After spending weeks perfecting a real-time chat system locally, I confidently pushed it to the production server\u2014only to watch the real-time features fail and the frontend flood the console with WebSocket connection errors. WebSocket connections were dropping, SSL handshakes were failing, and my beautiful real-time app became a very expensive paperweight.<\/p>\n\n\n\n<p>If you&#8217;re reading this, you&#8217;re probably in the same boat. Don&#8217;t worry \u2013 I&#8217;ve learned from those painful mistakes, and I&#8217;m going to walk you through exactly how to deploy Laravel Reverb to production without losing your sanity (or your users).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/deploy-laravel-reverb-to-production-1024x683.jpg\" alt=\"\" class=\"wp-image-1024\" srcset=\"https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/deploy-laravel-reverb-to-production-1024x683.jpg 1024w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/deploy-laravel-reverb-to-production-300x200.jpg 300w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/deploy-laravel-reverb-to-production-768x512.jpg 768w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/deploy-laravel-reverb-to-production.jpg 1536w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Reverb Server Deployment Steps<\/h2>\n\n\n\n<p>There are only three steps involved in starting the Reverb server on your VPS alongside your Laravel application. We assume that Reverb and all necessary packages (including the core broadcasting package) are already installed in your Laravel application. First, we configure the environment variables such as keys and ports. Then, we start the Reverb server using Linux\u2019s systemd to keep it running in the background. Finally, we configure the Nginx file to serve the application on your domain for use in your web applications.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step #01 &#8211; Environment Variables<\/h3>\n\n\n\n<p>You need to create or update the following variables in your Laravel application&#8217;s&nbsp;<strong><code>.env<\/code><\/strong>&nbsp;file. By default, the Reverb installation adds a few variables, but they are not sufficient for production deployment, so we must manually define them.<\/p>\n\n\n\n<p>The credentials should be defined exactly as shown in the image below. Set&nbsp;<strong><code>BROADCAST_CONNECTION<\/code><\/strong>&nbsp;to&nbsp;<strong>reverb&nbsp;<\/strong>so your app use reverb instead of PusherJS to file e.t.c. Ensure that the random string values,&nbsp;<code><strong>REVERB_APP_KEY<\/strong><\/code>&nbsp;&amp;&nbsp;<strong><code>REVERB_APP_SECRET<\/code><\/strong>, are unique and do not match each other. Keep them private and do not share them. The&nbsp;<code><strong>REVERB_HOST<\/strong><\/code>&nbsp;value should match your actual Laravel application\u2019s domain, but it must not include&nbsp;<strong><code>https:\/\/<\/code><\/strong>\u2014keep it simple (e.g.,&nbsp;<strong><code>example.com<\/code><\/strong>).<\/p>\n\n\n\n<p>You can change the port if the default one is already in use. This port will be referenced in the systemd and Nginx configuration files in the following steps, so make sure to remember it.<\/p>\n\n\n\n<p>If you make any changes to these values in the future, be sure to rebuild your project using the&nbsp;<strong><code>npm run build<\/code><\/strong>&nbsp;command otherwise new configurations will not work.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"934\" src=\"https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-env-file-values-1024x934.png\" alt=\"\" class=\"wp-image-1025\" srcset=\"https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-env-file-values-1024x934.png 1024w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-env-file-values-300x274.png 300w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-env-file-values-768x700.png 768w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-env-file-values-1536x1401.png 1536w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-env-file-values.png 1702w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Step #02 &#8211; Systemd Background Service<\/h3>\n\n\n\n<p>In this step, we will create a systemd service on Linux to run the Reverb server. This is a background service that starts and keeps the Reverb server running. In case the server crashes or your VPS restarts, the Reverb server will automatically come back online during the reboot process, ensuring zero downtime in production.<\/p>\n\n\n\n<p>I&#8217;ve named my systemd service&nbsp;<strong><code>reverb-server.service<\/code><\/strong>, but you can choose any name you prefer.<\/p>\n\n\n\n<p>You need to create this systemd file in the&nbsp;<strong><code>\/etc\/systemd\/system<\/code><\/strong>&nbsp;directory. In the example below, I\u2019ve used&nbsp;<strong><code>\/var\/www\/laravel<\/code><\/strong>&nbsp;as the Laravel application path\u2014make sure to update it with the correct path to your own Laravel application. Update this path in both the&nbsp;<strong><code>ExecStart<\/code><\/strong>&nbsp;and&nbsp;<strong><code>WorkingDirectory<\/code><\/strong>&nbsp;options.<\/p>\n\n\n\n<p>The&nbsp;<strong><code>User<\/code><\/strong>&nbsp;and&nbsp;<strong><code>Group<\/code><\/strong>&nbsp;can be set to&nbsp;<strong><code>www-data<\/code><\/strong>&nbsp;since we&#8217;re using Nginx. However, if Reverb doesn&#8217;t start properly under&nbsp;<strong><code>www-data<\/code><\/strong>, you can change it to&nbsp;<strong><code>root<\/code><\/strong>&nbsp;as a fallback.<\/p>\n\n\n\n<p>Here is what the systemd service file should look like:<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"609\" data-id=\"1028\" src=\"https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-systemd-file-configuration-simple-1024x609.png\" alt=\"\" class=\"wp-image-1028\" srcset=\"https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-systemd-file-configuration-simple-1024x609.png 1024w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-systemd-file-configuration-simple-300x178.png 300w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-systemd-file-configuration-simple-768x457.png 768w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-systemd-file-configuration-simple.png 1248w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<p>Once you have configured the systemd file, you need to reload the&nbsp;<strong><code>systemd daemon<\/code><\/strong>, then enable and start (or restart) the service. You can check the status of your systemd service to ensure it is running correctly using the&nbsp;<strong><code>systemctl status reverb-server<\/code><\/strong>&nbsp;command. following image contains all systemd commands you will need for the service.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"836\" data-id=\"1030\" src=\"https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-systemd-file-configuration-1-1024x836.png\" alt=\"\" class=\"wp-image-1030\" srcset=\"https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-systemd-file-configuration-1-1024x836.png 1024w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-systemd-file-configuration-1-300x245.png 300w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-systemd-file-configuration-1-768x627.png 768w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-systemd-file-configuration-1-1536x1253.png 1536w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-systemd-file-configuration-1.png 1544w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Step #03 &#8211; Nginx Configuration<\/h3>\n\n\n\n<p>Finally, we need to configure the Nginx config file to make Reverb work on the same domain as your Laravel app. Note that it&#8217;s also possible to deploy Reverb on a different domain or server and share it across multiple Laravel applications. However, in that case, you must provide the Reverb server credentials in the&nbsp;<strong><code>.env<\/code><\/strong>&nbsp;file of each Laravel app.<\/p>\n\n\n\n<p>In our case, we are aiming for a monolithic architecture\u2014keeping everything on a single server and domain, if it makes sense for your setup.<\/p>\n\n\n\n<p>To proceed, open your existing Laravel app\u2019s Nginx configuration file, usually located in&nbsp;<strong><code>\/etc\/nginx\/sites-available\/<\/code><\/strong>. This file contains the domain name of your Laravel app.<\/p>\n\n\n\n<p>You\u2019ll need to add the&nbsp;<strong><code>location \/app { ... }<\/code><\/strong>&nbsp;block for Reverb at the end of the relevant&nbsp;<strong><code>server { ... }<\/code><\/strong>&nbsp;block. Be careful\u2014if you&#8217;re using Certbot for SSL, it often creates an additional&nbsp;<strong><code>server { ... }<\/code><\/strong>&nbsp;block at the end of the file. Make sure you paste the Reverb block into the correct&nbsp;<strong><code>server { ... }<\/code><\/strong>&nbsp;section\u2014the one that contains the&nbsp;<strong><code>server_name<\/code><\/strong>&nbsp;for your Laravel app.<\/p>\n\n\n\n<p>Also, make sure the port number in the Reverb block matches the one you set in your Laravel app\u2019s&nbsp;<strong><code>.env<\/code><\/strong>&nbsp;file and in the systemd service. Once everything looks correct, save the file and restart Nginx.<\/p>\n\n\n\n<p>If you&#8217;re using&nbsp;<strong>Laravel Octane<\/strong>, don\u2019t forget to restart it as well. If all configurations are set up properly, your application should run without issues.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"797\" data-id=\"1032\" src=\"https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-nginx-configuration-file-2-1024x797.png\" alt=\"\" class=\"wp-image-1032\" srcset=\"https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-nginx-configuration-file-2-1024x797.png 1024w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-nginx-configuration-file-2-300x234.png 300w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-nginx-configuration-file-2-768x598.png 768w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-nginx-configuration-file-2-1536x1196.png 1536w, https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/reverb-nginx-configuration-file-2-2048x1595.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Quick Information:&nbsp;This post assumes that your core Laravel application is already working, has reverb package already installed and being served on a domain. We will configure Nginx, create a systemd service to start Reverb, and set the correct environment variables to ensure Reverb works properly. So you&#8217;ve built that amazing real-time chat feature with Laravel [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1024,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1023","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-deploying-laravel"],"jetpack_featured_media_url":"https:\/\/www.ystsol.com\/blog\/wp-content\/uploads\/2025\/06\/deploy-laravel-reverb-to-production.jpg","_links":{"self":[{"href":"https:\/\/www.ystsol.com\/blog\/wp-json\/wp\/v2\/posts\/1023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ystsol.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ystsol.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ystsol.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ystsol.com\/blog\/wp-json\/wp\/v2\/comments?post=1023"}],"version-history":[{"count":1,"href":"https:\/\/www.ystsol.com\/blog\/wp-json\/wp\/v2\/posts\/1023\/revisions"}],"predecessor-version":[{"id":1033,"href":"https:\/\/www.ystsol.com\/blog\/wp-json\/wp\/v2\/posts\/1023\/revisions\/1033"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ystsol.com\/blog\/wp-json\/wp\/v2\/media\/1024"}],"wp:attachment":[{"href":"https:\/\/www.ystsol.com\/blog\/wp-json\/wp\/v2\/media?parent=1023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ystsol.com\/blog\/wp-json\/wp\/v2\/categories?post=1023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ystsol.com\/blog\/wp-json\/wp\/v2\/tags?post=1023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}