Use Laravel's Maintenance Mode

Table of Contents

Introduction

Laravel includes a maintenance mode, which should be used whenever you need to modify your website. When your website is in maintenance mode, all visitors will be directed to a maintenance message page. This gives you the ability to communicate the downtime gracefully, instead of visitors seeing a series of Laravel error output messages. Learn how to put Laravel in and out of maintenance mode, and how to customize the maintenance message.

Requirements

  • A 1&1 Cloud Server with PHP and Laravel installed.

To install Laravel, follow the instructions in our article Install the Laravel PHP Framework on Ubuntu 16.04.

A Note on Permissions

In order to bring the site in and out of maintenance mode, Laravel creates a file in the storage directory. Be sure to run the chown command as shown in these instructions.

If the storage directory is owned by the www-data user, the php artisan up command will report "Application is now live" on the command line, but the site will still be in maintenance mode.

Start Maintenance Mode

Before you start maintenance mode, run the following command to give Laravel permissions to access the storage directory. Replace jdoe with your user name:

sudo chown -R jdoe:jdoe storage

Then use the following command to start maintenance mode:

php artisan down 

This will put Laravel into maintenance mode. All visitors will be directed to the default maintenance message.

Laravel maintenance mode

Stop Maintenance Mode

After you have finished making changes to your website, use the following command to end maintenance mode:

php artisan up

Then change permissions on the storage directory to the web user:

 sudo chown -R www-data:www-data storage

The site will return to normal functionality.

Customize Laravel's Maintenance Mode Message

To customize the Laravel maintenance page, edit the 503 Blade template:

nano resources/views/errors/503.blade.php

We recommend customizing the Laravel maintenance message with your existing site's design. You can also add custom text to the message, to give your visitors an explanation of the outage ("We are currently performing scheduled maintenance") or an estimate of the outage length ("Please check back in a few minutes").

Comments

Tags: Laravel / PHP