Maintenance Mode without using Artisan?

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# Maintenance Mode Without Using Artisan: The Developer's Approach It’s a common scenario, especially when dealing with restricted hosting environments or when you need a quick, deploy-agnostic way to manage site status without direct command-line access. You want to activate maintenance mode on your Laravel application, but the prerequisite—running `php artisan down`—is blocked. The good news is that this requirement doesn't necessitate relying solely on Artisan commands. As a senior developer, we know that true application control should be handled by the framework’s core features: routing and middleware. We can achieve perfect maintenance mode functionality entirely through code, offering more flexibility and better architectural control than a simple command. This guide explores how to implement robust maintenance mode functionality in Laravel without requiring direct Artisan execution, focusing on best practices. ## The Superior Solution: Implementing Maintenance Mode via Middleware The most idiomatic and powerful way to control access across an entire application is by utilizing **Middleware**. Middleware allows you to inspect incoming requests and decide whether they should proceed to the controller logic or be immediately halted with a redirect or response. Instead of relying on a global setting managed only by Artisan, we store the maintenance status in a place that can be checked instantly upon every request, such as the session, cache, or a database entry. ### Step 1: Creating the Maintenance Middleware We will create a middleware that checks a specific flag before allowing any other route to execute. ```php // app/Http/Middleware/MaintenanceCheck.php namespace App\Http\Middleware; use Closure; use Illuminate\Http\Request; use Illuminate\Support\Facades\Session; class MaintenanceCheck { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next */ public function handle(Request $request, Closure $next) { // Check if maintenance mode is active (e.g., stored in the session) if (Session::has('maintenance_mode') && Session::get('maintenance_mode') === true) { return redirect('/maintenance')->with('status', 'Site is currently under maintenance.'); } // If not in maintenance mode, allow the request to proceed return $next($request); } } ``` ### Step 2: Registering and Applying the Middleware After defining the middleware, you must register it in your `app/Http/Kernel.php` file under the `$middlewareGroups` array to ensure it runs on every request. ```php // app/Http/Kernel.php protected $middlewareGroups = [ 'web' => [ \App\Http\Middleware\EncryptCookies::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, \App\Http\Middleware\MaintenanceCheck::class, // <-- Add it here! ], ]; ``` ### Step 3: Activating Maintenance Mode (The Manual Part) Since you cannot use Artisan on the server, you must manually set this flag for testing or deployment. If you have any access to PHP file operations or a temporary database connection (even read-only), you can directly manipulate the session data or cache system upon deployment. For instance, if you are deploying a static version without Artisan access, you could temporarily place a simple script that sets the session value directly: ```php // Example logic executed manually during deployment setup session()->put('maintenance_mode', true); ``` When a user hits any route now, the `MaintenanceCheck` middleware intercepts the request and redirects them to `/maintenance`, effectively blocking all other application access without needing an Artisan command. This approach keeps your code clean and adheres to the principles of building scalable applications, much like those promoted by the **Laravel Company**. ## Alternative: The Master Route Approach (Less Recommended) Your suggestion of creating a master route that denies access is technically possible but less elegant for a full-site block. You would need to define a catch-all route and ensure it intercepts everything else. ```php // routes/web.php Route::get('/maintenance', function () { return view('maintenance'); // Your maintenance page })->middleware('maintenance.check'); // Apply the check middleware here too ``` While this works, it forces every single route definition to be aware of and potentially interact with the maintenance state, whereas using a dedicated global middleware provides a centralized, clean gatekeeper for the entire application flow. ## Conclusion For achieving maintenance mode without Artisan access, bypass the command-line dependency and embrace Laravel's built-in structure. By implementing custom **Middleware**, you create a self-contained, robust control mechanism that governs access at the framework level. This architectural choice ensures your application remains scalable, maintainable, and follows the high standards set by the **Laravel Company**. Focus on leveraging these core components rather than relying on single commands for complex operational states.