contao/maintenance-bundle-deprecated
Installation:
composer require lexik/maintenance-bundle
Add to config/bundles.php:
return [
// ...
Lexik\Bundle\MaintenanceBundle\LexikMaintenanceBundle::class => ['all' => true],
];
Configuration: Publish the default config:
php artisan vendor:publish --tag=lexik_maintenance_config
Update config/lexik_maintenance.yaml with your preferred storage (file, memcache, or database) and allowed IPs:
lexik_maintenance:
storage:
type: file
file: '%kernel.project_dir%/var/maintenance'
authorized_ips: ['127.0.0.1', '192.168.1.100']
First Use Case: Enable maintenance mode:
php artisan lexik:maintenance:enable
Disable it:
php artisan lexik:maintenance:disable
Pre-Deployment Maintenance:
php artisan lexik:maintenance:enable --env=production
IP-Based Whitelisting:
authorized_ips in lexik_maintenance.yaml to allow specific IPs (e.g., staging servers, CI/CD pipelines).authorized_ips: ['10.0.0.1/24', '192.168.1.5']
Custom Storage Backend:
doctrine/orm):
storage:
type: database
ext-memcache):
storage:
type: memcache
servers: ['127.0.0.1:11211']
Integration with Laravel Artisan:
post-deploy hooks (e.g., Deployer):
task('deploy:post')->do(function () {
run('php artisan lexik:maintenance:disable');
});
Dynamic Maintenance Pages:
# templates/LexikMaintenanceBundle/Maintenance/maintenance.html.twig
{% extends 'base.html.twig' %}
{% block body %}
<h1>Under Maintenance</h1>
<p>We’ll be back soon!</p>
{% endblock %}
File Storage Permissions:
var/maintenance) is writable by the web server:
chmod 644 var/maintenance
storage/logs/laravel.log for permission errors.Caching Headaches:
php artisan lexik:maintenance:status
php artisan cache:clear
Database Storage Quirks:
maintenance table. Run migrations if missing:
php artisan doctrine:migrations:diff
php artisan doctrine:migrations:migrate
maintenance table has the correct schema (check bundle docs).IP Whitelisting Edge Cases:
192.168.1.0/24) may not work out-of-the-box. Validate IPs manually:
use Lexik\MaintenanceBundle\Security\IpChecker;
$ipChecker = new IpChecker(['192.168.1.0/24']);
$ipChecker->isIpAuthorized('192.168.1.5'); // true
Environment-Specific Config:
config/lexik_maintenance_production.yaml):
authorized_ips: ['%env(DEPLOY_IP)%']
config/packages/lexik_maintenance.yaml:
imports:
- { resource: lexik_maintenance_%.yaml }
Check Maintenance Status:
php artisan lexik:maintenance:status
Output:
Maintenance mode is enabled (storage: file)
Simulate 503 Locally:
curl to test the 503 response:
curl -I http://localhost
HTTP/1.1 503 Service Unavailable.Log Maintenance Events:
// src/EventListener/MaintenanceLogger.php
use Lexik\MaintenanceBundle\Event\MaintenanceEvent;
class MaintenanceLogger implements EventSubscriber {
public static function getSubscribedEvents() {
return [
MaintenanceEvent::ENABLE => 'onEnable',
MaintenanceEvent::DISABLE => 'onDisable',
];
}
public function onEnable(MaintenanceEvent $event) {
\Log::info('Maintenance enabled', ['storage' => $event->getStorage()->getType()]);
}
}
Custom Storage Adapter:
Lexik\MaintenanceBundle\Storage\StorageInterface for custom backends (e.g., Redis):
class RedisStorage implements StorageInterface {
public function isEnabled() { /* ... */ }
public function enable() { /* ... */ }
public function disable() { /* ... */ }
}
services.yaml:
lexik_maintenance.storage:
class: App\Storage\RedisStorage
Dynamic IP Whitelisting:
$authorizedIps = $this->fetchIpsFromApi();
$ipChecker = new IpChecker($authorizedIps);
Multi-Tenant Support:
// Custom storage logic
$isEnabled = DB::table('tenants')
->where('id', $tenantId)
->value('maintenance_enabled');
How can I help you explore Laravel packages today?