frenchbaguette
frenchbaguette

Reputation: 1339

Laravel 5 maintenance mode turn on without artisan

Is there any possibility to turn on and turn off Laravel 5 maintenance without php artisan up and down commands when my website is being hosted ?

What I've done:

Route::get('site/shutdown', function(){
    return Artisan::call('down');
});

Route::get('site/live', function(){
    return Artisan::call('up');
}); 

The first route is working fine. But when I call site/live the site still is shuted down. What can cause this problem ?

Upvotes: 33

Views: 55486

Answers (7)

Hasib Kamal Chowdhury
Hasib Kamal Chowdhury

Reputation: 2660

You cannot call another function if your project is already down.

After you run php artisan down, it creates a file named down inside storage/framework.

After running the php artisan up command the file is removed.

You can create the file manually inside the storage/framework. It will down your project. When you want to take your project live again, just remove the file.

Upvotes: 0

smartrahat
smartrahat

Reputation: 5649

If your project is already down, you cannot call another function.

What happens after you run php artisan down is that it creates a file named down inside storage/framework. After running php artisan up the file is removed.

You can create the file manually inside storage/framework. It will down your project. When you want to take your project live again, just remove the file.

Upvotes: 73

Amir Hossein Abdollahi
Amir Hossein Abdollahi

Reputation: 1403

Laravel 8 introduced secret in maintenance mode, in which you can bypass the maintenance mode by providing a secret, then your Artisan::call would work.

You could add your routes to the $except var in CheckForMaintenanceMode middleware to bypass the check. Then your site/live route would work just fine.

Upvotes: 3

Vaheed01
Vaheed01

Reputation: 1067

I think the right answer is missing here.. You could add your route to app/http/middleware/CheckForMaintenanceMode.php

protected $except = [
        //here
];

So It never would be off.

Upvotes: 6

Khairul Hafizi
Khairul Hafizi

Reputation: 79

just put

Artisan::call('up');

without route function.

Upvotes: 1

Mohamed Coder
Mohamed Coder

Reputation: 61

when you run artisan down. site is not available so when try to call up, your IP can't access site. you must call down with your IP exception.

php artisan down --allow=127.0.0.1 --allow=192.168.0.0/16

or add ::1 to local.

to make that in route without command try to save this command in specific one and call it.

Upvotes: 5

Szaby
Szaby

Reputation: 39

In order to make your site live again using an url, you can create a live.php file which you put in laravel's public folder and then visit http://your.domain/live.php .

In the live.php file you need something like this: (check your projects directory structure if you don't use the default public folder!)

<?php
unlink(dirname(__FILE__) . "/../storage/framework/down");
header("Location: your.domain"); 
die;

Upvotes: 2

Related Questions