I'm just wondering if anyone know's if there's a way to activate maintenance mode on a laravel website without using Artisan? I don't have command line access to the server so I can't use Artisan without first updating it on my local site and then push the changes to the server. Is there maybe a master Route that I can add that will deny access to any other routes?
Thanks!
Laravel 4
Just wanted to put this out there for everyone on the web, all
php artisan down
does is touch (create) an empty file in theapp/storage/meta
directory called 'down'. If this file exists, then the application is in maintenance mode. That's all there is to it:So if you can upload files, all you need to do is upload an empty file named 'down' to
app/storage/meta
.Laravel 5:
Down is located in
storage/framework/down
Thanks ruuter.
In laravel 5.6, the location of the "down" file has moved slightly.
It's new location is:
./storage/framework/down
Laravel 5.6 has added some contents to the "down" file, although an empty file is still effective. You get a "503 Service Unavailable" page, by default.
Simply remove the "down" file when you're finished.
The real correct answer to question is above provided by Antonio.
Laravel 5+
Since middleware(s) were introduced in Laravel 5, I will cover how I do it in Laravel 5.3 application.
Create brand new middleware
First lets create new middleware
$php artisan make:middleware CheckForMaintenanceMode
replace global middleware
Open up
App/Http/Kernel.php
and rewrite foundations middleware with our new middlewareIf application is in maintenance mode (down) we can still access login page or any
admin/*
page.This is for Laravel 4.1 and below
Laravel 5 downfile is in
storage/framework/down
- thanks @ruuter.Taking a look at the
DownCommand
class for Artisan, it seems to create a new file within theapp/storage/meta
folder.Heres the
DownCommand
fire
method.And the corresponding
UpCommand
fire
method.These files are located in
vendor/laravel/framework/src/Illuminate/Foundation/Console
.It specifically creates a file called
down
inapp/storage/meta
.You could create an authorized route / controller action to replicate these commands.
Note Sjaak Trekhaa's comment below, that is the method I would use now that I've been reminded of it!
You can just call artisan from your application:
But since you'll not have access to get your app up because it's down. You can create the functionality yourself:
A route for shut it down, user must be authenticated to do this:
A route to bring it back up:
A filter to check if it's up:
A route to bring it back up:
A route to show a pretty view when your site is down