Enable maintenance mode on your site during scheduled maintenance and for other valid reasons using the WordPress Command Line Interface (WP-CLI) with ease.
How to Enable & Disable Maintenance Mode in WordPress Using WP-CLI
Why Enable Maintenance Mode
When you have extensive content updates, plugin updates, or changing out plugins on your WordPress site, it is worth putting your site into maintenance mode so that you can make those changes without users trying to access the site. By turning on maintenance mode, when site visitors go to access the site, then they are met with a message letting them know that site is being worked on.
This well communicated maintenance status for the site will allow you to be able to make the manual site changes or to administer a version control workflow push of planned changes if you are importing in content. In summary, making major changes on a site are best performed in a maintenance mode to avoid users encountering an error or other unexpected behaviors.
One logical use case of when maintenance mode should be enabled would be if you planned on changing a theme on the site. Instead of having the site be public while you installed and activated a new theme, maintenance mode should be turned on. Another logical user use care would be for the importing in the new customizer settings, which would lead to site visitors accessing the site in an incomplete and less than finished status if maintenance mode had not been turned on.
Another good reason why you would want to put your production site into maintenance mode would be if you are pushing changes from your staging or development site, and you can keep the maintenance mode enabled during that process. If you are on a non-cloud server, you could manually create a dev site to be able to make changes before those changes are pushed manually or using a version control workflow to the production site.
WordPress enables maintenance mode using .maintenance file that would be created in the site's public HTML folder on the site's server. Maintenance mode would automatically be enabled when you update plugins or themes from within wp-admin.
With maintenance mode enabled on your site, when you or a site visitor goes to access the site URL, the browser will display the following message:
Briefly unavailable for scheduled maintenance. Check back in a minute.
How to Use WP-CLI
To be able to use WP-CLI on your site, you will need to have logged into the Nexcess Portal to find and get the SSH credentials for the site's server. It is recommended to use a command-line application to use WP-CLI. For example, a macOS device would already have the Terminal application installed, and on a Windows or Linux device, you can install the PuTTY application.
Valid Folder for WP-CLI
To use WP-CLI on your site's server, you will need to be in the correct folder of your WordPress installation. If you are not in the proper WordPress installation folder, then WP-CLI will not work. The command to change the directory to the WordPress installation would be:
cd public
Activate Maintenance Mode
To activate maintenance mode on your site, the WP-CLI command to run is:
wp maintenance-mode activate
You can also add the force flag to force activate the maintenance mode using this WP-CLI command:
wp maintenance-mode activate –force
Deactivate Maintenance Mode
When you have finished making changes on your site, then you can then deactivate the maintenance mode. You can do so by running the following command:
wp maintenance-mode deactivate
Is Maintenance Mode Active
If you quickly need to check if maintenance mode is active or not on your site, you can run the following command:
wp maintenance-mode is-active
Checking Maintenance Mode Status
To be able to check the status of maintenance mode on the site, you can run the following command:
wp maintenance-mode status
This will show if maintenance mode is activated or deactivated.
Why Maintenance Mode is Useful
First of all, being able to easily enable maintenance mode without having to install and activate a plugin to do so is a time saver. And being able to enable, deactivate, and check the status all from the command line using WP-CLI is very useful. Doing so allows you to be able to safely make updates on the site or push content changes without having site users deal with a site that is in the process of being updated. Therefore, the WP-CLI command is an essential part of a clear developer workflow.
A Final Real-World Example
A final real-world example of when you would want to enable maintenance mode on a production site is when you are running a final sync during a site migration. Having this mode turned on would allow the site not to have missing comments if you have comments enabled on posts on the site, nor to have missing form entries if you are using a form plugin which stores form entries in the site's database. If your site is used for ecommerce and you are using a plugin such as WooCommerce, you would have products, customers, or orders to deal with. It is recommended to keep the production site set in maintenance mode until the final sync migration has been completed.
Hopefully, this article explains why maintenance mode as a built-in feature in WordPress is important to use and how to enable, deactivate, and check its status on a site while using WP-CLI commands to change and check maintenance mode.
Using Managed WordPress for your site hosting will make your site hosting easier and help your site's performance.
Useful Links Related to WordPress Maintenance Mode
- https://developer.wordpress.org/cli/commands/maintenance-mode/
- https://developer.wordpress.org/cli/commands/maintenance-mode/activate/
- https://developer.wordpress.org/cli/commands/maintenance-mode/deactivate/
- https://developer.wordpress.org/cli/commands/maintenance-mode/is-active/
- https://developer.wordpress.org/cli/commands/maintenance-mode/status/
- https://github.com/wp-cli/maintenance-mode-command
- https://make.wordpress.org/cli/handbook/guides/common-issues/
- https://developer.wordpress.org/cli/commands/cli/info/
Other Useful WordPress Links for Developers & Admins
- https://wp-cli.org/#using
- https://help.nexcess.net/74095-wordpress/locating-your-ssh-credentials-in-managed-wordpress-and-managed-woocommerce-hosting
- https://developer.wordpress.org/cli/commands/db/search/
- https://developer.wordpress.org/cli/commands/db/size/
- https://developer.wordpress.org/cli/commands/db/search/#options
- https://make.wordpress.org/cli/handbook/guides/common-issues/
- https://make.wordpress.org/cli/handbook/guides/troubleshooting/
- https://make.wordpress.org/cli/handbook/guides/identify-plugin-theme-conflict/
- https://make.wordpress.org/cli/handbook/contributions/bug-reports/
- https://developer.wordpress.org/cli/commands/cli/info/https://developer.wordpress.org/cli/commands/theme/list/
- https://developer.wordpress.org/cli/commands/theme/update/
- https://developer.wordpress.org/cli/commands/plugin/list/
- https://developer.wordpress.org/cli/commands/plugin/update/
- https://help.nexcess.net/74095-wordpress/wordpress-automatic-updates
- https://help.nexcess.net/74095-wordpress/how-to-enable-auto-updates-for-plugins-and-themes
About the Nexcess Portal
Starting with a new hosting partner can be overwhelming. For that exact reason, we have prepared a Nexcess Portal Guide to make each client’s introduction to our Nexcess Portal easier.
How to Become a Nexcess Portal Pro
You signed up for an account with Nexcess but now what do you do? New systems can be intimidating to learn, so we’ve put together this guide to help explain what is in the portal and where to find it.
Next Steps?
Read more about the Fully Managed WordPress Hosting and its benefits for your business.
Build Better Websites with Fully Managed WordPress Hosting
It’s hosting optimized for WordPress. That means a faster, more secure and scalable website. Smart monitoring tools are built-in to help you keep it that way.
It’s why WordPress Users Trust Nexcess Hosting.
We also have a variety of Nexcess support articles about WordPress, including how to get your site going with a number of different configuration options. These resources include a great article on setting this up for Migrating to Nexcess with managed WordPress and managed WooCommerce hosting.
24-Hour Assistance
If you need any assistance with the above-mentioned, don't hesitate to reach out. For 24-hour assistance any day of the year, Nexcess customers can contact our support team by email or through your Client Portal.
Useful YouTube > Nexcess Channel Links
- https://www.youtube.com/watch?v=OAHwmysUd-8
- https://www.youtube.com/c/nexcessnet-1/
- https://www.youtube.com/c/nexcessnet-1/featured
- https://www.youtube.com/c/nexcessnet-1/videos
-
https://www.youtube.com/c/nexcessnet-1/playlists
Resources for More Information
Need more help? The Applications, WooCommerce, and WordPress sections within the Nexcess Knowledge Base are important resources for those seeking additional knowledge. Or, check out our related articles below.
New Customers: Fully Managed Hosting Solutions
Not a Nexcess customer yet? Check out our fully managed hosting solutions. The option to chat with an expert is also available.
Related Articles
- Scope of Support
- Getting started with managed WordPress and WooCommerce hosting
-
Migrating to Nexcess with managed WordPress and managed WooCommerce hosting
- Going live with your site in Managed WordPress and Managed WooCommerce hosting
- WordPress Cleanup 101: 9 Easy Ways To Clean Up and Optimize Your WordPress Site
- How to configure the Nexcess CDN with WordPress and CDN Enabler
- The Nexcess Plugin Performance Monitor
- Viewing AWStats for Managed WordPress & WooCommerce