Deploying your app is a crucial part in any web deployment. During large deployment following things are essentials:
- Making sure not to allow write to db during maintenance mode
- Making sure users are not able to access different part of the application
- Making sure you notify customer for upcoming deployments or maintenance window
For simple deployment where you do not need to make too many changes to either server or on database you still want to handle your deployment as smooth as possible.
Laravel handles maintenance for you without any headache. When your application is in maintenance mode, a custom view will be displayed for all requests into your application.
This makes it easy to "disable" your application while it is updating or when you are performing maintenance. To enable maintenance mode, followings are some useful laravel commands related to maintenance mode:
# enable maintenance mode
php artisan down
# disable maintenance mode
php artisan up
# if you want client to refresh
# page after specified number of seconds
php artisan down --retry=60
How to test app while app under maintenance in laravel?
As you know when you turn on the laravel maintenance mode it wont allow you to perform write operations however, if you still need to test your web app with new changes where you need to write to db you can bypass maintenance mode.
Even while in maintenance mode, you may use the
secret option to specify a maintenance mode bypass token:
php artisan down --secret="1630542a-246b-4b66-afa1-dd72a4c43515"
Once you inform down command with secret provided as an argument you can hit following url to set cookie that will let you bypass maintenance mode on your browser using following url:
When accessing this hidden route, you will then be redirected to the
/ route of the application. You will be able to browse the application normally as if it was not in maintenance mode.
How to use custom view for maintenance mode in laravel?
You can inform laravel to render specific view when running maintenance mode. Try following command:
# view path: resources/views/maintenance.blade.php
php artisan down --render="maintenance"
How to redirect all request to home page in maintenance mode in laravel?
Sometime you may wish all your visitor not to access any of your webpages other than homepage during the maintenance mode. In that case you can redirect all of your web request to specified url using following command:
php artisan down --redirect=/
During maintenance mode job queues will not work. Hope you enjoyed this topic send me some more suggetions that you like using my contact form.