sudo -u www-data php occ maintenance:mode --on sudo -u www-data php occ maintenance:mode --off
Turn maintenance mode on- or off by first navigating to your Nextcloud root folder. E.g. /var/www/mynextcloud and running the relevant command. E.g:
sudo -u www-data php occ maintenance:mode --on
Like many other things, maintenance mode can be controlled with the occ CLI management tool that comes with Nextcloud.
As an alternative option that might be even safer than placing your Server in maintenance mode, you can also simply stop the relevant services and start them again when you are done performing maintenance. E.g. the Apache HTTP server:
systemctl stop apache
Due to the nature of some tasks. E.g. Switching your Nextcloud domain name or moving your Nextcloud data directory, you may want to stop the relevant services entirely until you are done.
It is also generally a good idea to put your server in maintenance mode while taking backups with tools like tar.
- Maintenance commands - docs.nextcloud.com