Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mikebronner's avatar

[Laravel 5] Maintenance Mode?

How do I enable maintenance mode in L5? :)

0 likes
24 replies
Puretears's avatar

Just execute php artisan down command. :-)

2 likes
mikebronner's avatar

Haha, ya -- sorry, forgot to be more explicit: what is the equivalent of App::down() that used to be in global.php and where does it go now?

1 like
Puretears's avatar

It seemed that you could create a file named 'down' in storage/framework folder to enable maintenance mode. :-)

2 likes
mikebronner's avatar

Well, shucks, I should explain what I want more clearly. :) In Laravel 4.x you can specify an App::down() method in /app/start/global.php to provide custom handling. In my case I am returning a custom view to show that the site is under maintenance, or coming soon, like so:

App::down(function()
{
    return View::make('comingSoon');
//  return Response::make("Be right back!", 503);
});

Where would I do the equivalent of this in Laravel 5?

mikebronner's avatar

I don't see a global.php file anywhere in Laravel 5 ... at least not when I created a project using composer create-project?

mikebronner's avatar

That's the larval 3 branch you are looking at? The develop branch doesn't have that file.

xingfucoder's avatar

Sorry I copied the fail link because when you search into the develop version appears this file.

xingfucoder's avatar

See here:

app\Http\Middleware\MaintenanceMiddleware.php

I think is one of the new features of Laravel 5.

Sorry the last post.

xingfucoder's avatar

Because of this is a new characteristic in Laravel, be careful using it and check the repository when you need to use it newly.

mikebronner's avatar

Yea, I had no idea where to start looking. Because of this and other potential pitfalls, and my project being something I want to push to production sooner than later, I reverted back down to 4, and will upgrade later. :)

Nevertheless, always good to learn what changes. :) Thanks for digging this up!

1 like
xingfucoder's avatar

You are welcome. I downloaded the github zip file, unzip it and read from SublimeText searching the down method, and it returns the file that I put here.

For something similar you can use this way.

AnthonyIfon's avatar

Did anybody were this now is in 4 I could do

App::down(function()
{
    if ( ! in_array(Request::getClientIp(), ['86.10.190.248','86.4.7.24']))
    {
        return Response::make("Be right back!", 503);
    }
});

To develop on a real server but I can seem to find a similar function in 5

toniperic's avatar
Level 30

@AnthonyIfon you can now create your own middleware for this.

For example create a file at app/Http/Middleware/CheckForMaintenanceMode.php with the following content:

<?php namespace App\Http\Middleware;

use Closure;
use Illuminate\Contracts\Routing\Middleware;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;

class CheckForMaintenanceMode implements Middleware {
    
    protected $request;
    protected $app;

    public function __construct(Application $app, Request $request)
    {
        $this->app = $app;
        $this->request = $request;
    }

    public function handle($request, Closure $next)
    {
        if ($this->app->isDownForMaintenance() && 
            !in_array($this->request->getClientIp(), ['86.10.190.248', '86.4.7.24']))
        {
            return response('Be right back!', 503);
        }

        return $next($request);
    }

}

All you have to do is swap the Illuminate's CheckForMaintenanceMode middleware for your implementation, by opening the file app/Http/Kernel.php and replacing line

'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode'

with

'App\Http\Middleware\CheckForMaintenanceMode'
9 likes
JonMorrison99's avatar

If your looking for a manual method to enable maintenance mode in LV-5 all you need to do is create an empty txt file called 'down' under /storage/framework

example /storage/framework/down

Combine this the middleware solution above and you have a nice little way to put your application in and out of maintenance mode via code.

1 like
deantedesco's avatar

I know this has been answered with a perfectly valid way of doing it but there is another way to do this by utilising the App\Exceptions\Handler class in Laravel. I use this method to give the response a message for my API's so my example will be for an API based system but is easily modified for a site as well. This method however does not account for the exceptions rules for IP addresses that will bypass the maintenance mode, however you can still use this method for all your messages on exceptions of any kind.

In your Handler.php file add the following to your render method - entire Handler.php file shown.

<?php

namespace App\Exceptions;

use Exception;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that should not be reported.
     *
     * @var array
     */
    protected $dontReport = [
        HttpException::class,
    ];

    /**
     * Report or log an exception.
     *
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     *
     * @param  \Exception $e
     *
     * @return void
     */
    public function report(Exception $e)
    {
        parent::report($e);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Exception               $e
     *
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $e)
    {
        if ($e instanceof HttpException) {
            return response()->json(
                [
                    'error' => [
                        'message'     => "This app is currently undergoing maintenance.",
                        'status_code' => 503,
                    ],
                ],
                503
            );
        }

        return parent::render($request, $e);
    }
}

Please or to participate in this conversation.