Installation
composer require devtia/maintenance-bundle
Add the bundle to AppKernel.php (or config/bundles.php in Symfony 4+):
new Devtia\MaintenanceBundle\MaintenanceBundle(),
Enable Maintenance Mode
Update config/packages/devtia_maintenance.yaml (or config.yml in older versions):
maintenance:
enable_maintenance: true
First Use Case Deploy your code, and the default maintenance page will immediately activate. No additional configuration is needed for a full-site maintenance mode.
Toggle Maintenance Mode
Enable/disable via enable_maintenance in config. Useful for zero-downtime deployments:
# config/packages/devtia_maintenance.yaml
maintenance:
enable_maintenance: true # Set to false to exit maintenance
Route-Specific Maintenance Define regex-matched routes with custom templates:
maintenance:
routes_prefixes:
- ['\/admin\/', '%kernel.project_dir%/templates/maintenance/admin.html.twig']
- ['\/api\/', '@Maintenance/custom_api.html.twig']
\/admin\/.* for all admin routes).@Bundle/) or absolute paths.Dynamic Configuration
Override settings per environment (e.g., config/packages/devtia_maintenance_dev.yaml):
maintenance:
enable_maintenance: false # Disable in dev
Integration with Deploy Scripts Automate toggling via CI/CD:
# Before deploy
sed -i 's/enable_maintenance: false/enable_maintenance: true/' config/packages/devtia_maintenance.yaml
git add config/packages/devtia_maintenance.yaml
git commit -m "Enable maintenance mode"
Regex Edge Cases
admin/ → \/admin\/).\/api\/ and \/api\/v1\/).preg_match() in a twig shell or php artisan tinker.Template Caching
php bin/console cache:clear
Symfony 4+ Compatibility
config/bundles.php (not AppKernel).config/packages/devtia_maintenance.yaml instead of config.yml.HTTP Caching Headers
503 Service Unavailable headers. Add middleware for stricter behavior:
// src/EventListener/MaintenanceListener.php
public function onKernelRequest(GetResponseEvent $event) {
if ($this->maintenanceEnabled) {
$event->setResponse(new Response('', 503));
}
}
Custom Templates
Extend the default template by copying vendor/devtia/maintenance-bundle/src/Resources/views/Maintenance/default.html.twig to your project (e.g., templates/maintenance/custom.html.twig).
Environment Variables
Use .env for dynamic toggling:
# config/packages/devtia_maintenance.yaml
maintenance:
enable_maintenance: '%env(bool:MAINTENANCE_MODE)%'
Then set MAINTENANCE_MODE=true in your environment.
Logging Maintenance Events Add a listener to log when maintenance is enabled/disabled:
// src/EventListener/MaintenanceLogger.php
public function onKernelRequest(GetResponseEvent $event) {
if ($this->maintenanceEnabled) {
\Log::info('Maintenance mode activated');
}
}
Whitelisting IPs Combine with firewall rules to allow specific IPs (e.g., your team’s IPs) to bypass maintenance:
# config/packages/security.yaml
firewalls:
main:
ip: 192.168.1.0/24 # Allow your office subnet
Testing
Mock the bundle in tests by overriding the MaintenanceChecker service:
$container->set('devtia_maintenance.maintenance_checker', $this->createMock(MaintenanceChecker::class));
How can I help you explore Laravel packages today?