We use cookies to understand how you interact with our site, to personalize and streamline your experience, and to tailor advertising. By continuing to use our site, you accept our use of cookies and accept our Privacy Policy.

Your Digital Commerce Experts
Nexcess Logo

Set WordPress Maintenance Mode Using WP-CLI

March 23, 2022


Set WordPress Maintenance Mode Using WP-CLI


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 settingswhich 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 siteand 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


Other Useful WordPress Links for Developers & Admins


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 WordPressincluding 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

Resources for More Information

Need more help? The Applications, WooCommerceand 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

Paul Stubblefield
Paul Stubblefield


Nexcess Knowledge Base Owner
Content Marketing in Nexcess Digital Marketing
Nexcess, A Liquid Web Brand

Paul Stubblefield
— Technical Writer & Knowledge Management Professional

"Delivering the next generation of life-enhancing technology platforms, software solutions, and mobile-ready applications for technology pioneers, thought leaders, and market innovators in a robustly connected world."

Paul lives in Bonita Springs, Florida, USA. He is an aficionado of art, coffee, good-natured humor, lifelong learning, music, nature, pets, technology, world cultures, and his Zen Patio Garden project.