You can use the console commands off and on to take the system offline or online, respectively. This bypasses the allowAdminChanges
setting and is explicitly intended for usage during deployments.
In fact, our deployment script for Craft projects uses this to take the system offline while the deployment is taking place:
# create db backup before deployment
php craft db/backup
# turn on maintenance mode
php craft off --retry=15
# pull, migrate, apply project config, etc
# turn off maintenance mode
php craft on
Update: System status with environment variables
Since Craft 3.7.22 you can use environment variables to manage the system status. See the release notes for details. If you're using a hosting solution that allows you to change the environment in your deployment script (either through an API or by writing to the .env
file directly), you can use that to take the system offline. This way, applying the project config won't change the system status.
Further improvements for this are planned for Craft 4, according to Brandon:
So I am thinking for Craft 4 we will:
- Deprecate
isSystemLive
- Repurpose Maintenance Mode to be the new primary way of determining whether the system is live, rather than having anything to do with updating (we are going to be dropping the ability to update within the control panel when Dev Mode isn’t enabled anyway, so conflicts aren’t a concern anymore)
- Drop
system.live
from the project config
See this issue on Github for details.