How to up or down Laravel Application Maintenance Mode and How it Works

Updated on ... 23rd October 2023

In this tutorial, we will focus on how the Laravel application maintenance mode works. Sometimes when we build Laravel applications, we aim to make our website/software uptime on a higher percentage, but from time to time we face situations that require us to go into maintenance mode. This situation may be due to bug fixing, database errors, server upgrade SSL errors, etc. Meanwhile, if you don’t want to show your application to customers then this single command helps you to down your application and the customer can only see a 503 customized service unavailable error page. 

php artisan down

Maintenance mode: The php artisan down command will put your application into maintenance mode it allows you to display a user-friendly service unavailable 503 page (which is a Laravel default error page you can also customize)  to your users instead of a broken site during website maintenance mode. 

It also allows you to perform any maintenance task safely while making changes, or upgrading the server or fixing any errors.


                                                    

                                                    

                                                    php artisan down

                                                    

                                                

This command has some optional flags:

--refresh

This flag sets a refresh header that will instruct the user browser to automatically refresh the page after the given number of seconds


                                                    

                                                    

                                                    php artisan down --refresh=15

                                                    

                                                

You Should Also Read

--secret

This flag helps to set an authorized token. After keeping the application in maintenance mode, you can visit the application by passing this secret token in the URL

like https://example.com/secret-token




                                                    

                                                    

                                                    php artisan down --secret="123@test_pass"

                                                    

                                                

--retry

You can also provide a retry flag with the down command, which will be set as the Retry-After HTTP header's value, however, the browser mostly ignores this header:




                                                    

                                                    

                                                    php artisan down --retry=60

                                                    

                                                

--render

This flag helps you to define a specific template to show your users during maintenance mode


                                                    

                                                    

                                                    php artisan down --render="errors::503"

                                                    

                                                

--redirect

During application in maintenance mode, Bydeffault Laravel will display the maintenance mode view (which is 503 page by default) for all application URLs the user attempts to access. 

If you want to redirect all requests to a specific URL you can pass this flag.



                                                    

                                                    

                                                    php artisan down --redirect=/

                                                    

                                                

Disabling Maintenance Mode or up your Application

After maintaining your application, you can make it live by using the below command, and this can be achieved using another artisan command:

This command does not have any flag


                                                    

                                                    

                                                    php artisan up

                                                    

                                                

How it works?

When you run php artisan down, this command will create a file named down inside storage/framework folder and when you run php artisan up the file will removed.

You can also create the file manually inside the storage/framework. It will down your project. When you want to make your project live again, only you have to remove this file.

you can see the file in your project like below screenshot after running the down command

This file contains below code:


                                                    

                                                    

                                                    {
    "except": [],
    "redirect": null,
    "retry": null,
    "refresh": null,
    "secret": null,
    "status": 503,
    "template": null
}

                                                    

                                                

Related Post

Leave a comment