This short snippet aim to easily handle setting a Symfony 5.*+ website to maintenance mode.
Certain users with defined roles can continue surfing on the site, usefull to allow team to test the app even in maintenance (See comments in MaintenanceListener.php file).
Please follow simply these steps to set up maintenance feature on your symfony powered website:
Copy the content of services.yaml (in this repo) to your config/services.yaml
Create src/Services/Listener/MaintenanceListener.php and copy the content of MaintenanceListener.php in it.
- Don't forget to customize your $allowRoutesInMaintenance to serve certains routes to public even in maintenance (login, etc)
- This is important for you (admin or team), to authenticate yourself before having full access to the site in maintenance
- Don't forget to set your twig templates path correctly.
Register your Listener in your config/services.yaml file or copy the content of services.yaml to your config/services.yaml
Create a twig template to server publicly in maintenance mode or see the maintenance.html.twig file in this repo
Happy hacking
Thank to be eP