Everything You Need to Know About Laravel's Maintenance Mode
Published on by Dasun Tharanga
2 min read✨ Introduction
Laravel's Maintenance Mode is a feature that helps manage temporary disruptions during website updates or maintenance tasks. When activated, it displays a customizable maintenance page to users, ensuring they are informed while minimizing disruption.
👩💻 Usage
The maintenance mode can be enabled within a second using the following artisan command:
1php artisan down
Of course, we can disable maintenance mode using the reverse command of the above command:
1php artisan up
But many developers miss out on other features it offers. 😥
Feature: Send Refresh HTTP Header
This feature will send a Refresh
HTTP header with all maintenance mode requests. It automatically refreshes the web page in given seconds.
You can provide the refresh
option when executing the down
command:
1php artisan down --refresh=30
Feature: Send Retry-After HTTP Header
You can also provide a retry
option to the down
command, which will be set as the Retry-After
HTTP header's value, but browsers usually ignore this header:
1php artisan down --retry=60
⏭️ Bypassing Maintenance Mode
Sometimes, many developers like to use the website even in maintenance mode for some reasons, this is where the secret
option comes into play.
The secret
option will take a secret token that we provide to bypass maintenance mode as shown below:
1php artisan down --secret="1630542a-246b-4b66-afa1-dd72a4c43515"
If you are in the maintaince mode, you can now navigate to the application's URL with the secret token:
1https://example.com/1630542a-246b-4b66-afa1-dd72a4c43515
If you want to let Laravel generate a secret token for you, you can use the following command:
1php artisan down --with-secret
💅 Pre-Rendering the Maintenance Mode View
Well, even with maintenance mode enabled, users still face some errors while updating your Composer dependencies or other infrastructure components.
The reason is that a significant part of Laravel needs to be initialized to determine that the application is under maintenance mode.
We can avoid this problem by using a pre-rendered template, because this view is rendered before the application's dependencies are loaded.
To do that, you may use the render
option with the down
command:
1php artisan down --render="errors::503"
↪️ Redirecting Maintenance Mode Requests
If you would like to redirect all maintainance requests to a specific URL, you may use the redirect
option with the down
command:
1php artisan down --redirect="https://example.com"
⚠️ Maintenance Mode and Queues
When your application in maintenance mode, Laravel does not handle queued jobs, these jobs will continue when the application goes live again.
I hope this helps! See you in the next post!