Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - artisan down / Maintenance Mode except own IP

Tags:

laravel

Currently i am using Laravel5. My question is if if i use the Maintenance mode with

php artisan down

how can say "the application is down for everyone except my own ip" ? So everyone is seeing the Maintenance mode, but i have still access to the site.

like image 523
user3633186 Avatar asked Jun 10 '15 09:06

user3633186


2 Answers

For Laravel 8:

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"

After placing the application in maintenance mode, you may navigate to the application URL matching this token and Laravel will issue a maintenance mode bypass cookie to your browser:

https://example.com/1630542a-246b-4b66-afa1-dd72a4c43515

When accessing this hidden route, you will then be redirected to the / route of the application. Once the cookie has been issued to your browser, you will be able to browse the application normally as if it was not in maintenance mode.

There some new nice features with maintenance mode in Laravel 8. Read it here.

like image 112
jewishmoses Avatar answered Sep 26 '22 04:09

jewishmoses


In Laravel 5 you have to create your own middleware. Create a file in app/Http/Middleware/CheckForMaintenanceMode.php You can choose of course any filename.

<?php namespace App\Http\Middleware;

use Closure;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as MaintenanceMode;

class CheckForMaintenanceMode {

    protected $app;

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

    public function handle(Request $request, Closure $next)
    {
        if ($this->app->isDownForMaintenance() && 
            !in_array($request->getClientIp(), ['8.8.8.8', '8.8.4.4']))
        {
            $maintenanceMode = new MaintenanceMode($this->app);
            return $maintenanceMode->handle($request, $next);
        }

        return $next($request);
    }

}

In your app/Http/Kernel.php change

'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode'

to

'App\Http\Middleware\CheckForMaintenanceMode'
like image 45
user3633186 Avatar answered Sep 22 '22 04:09

user3633186