How to Enable Maintenance Mode in WordPress: A Guide for SSH and SFTP
When it comes to managing your WordPress website, ensuring that everything runs smoothly during updates and migrations is crucial. One effective way to achieve this is by enabling maintenance mode. This feature temporarily restricts access to your site, allowing you to make necessary changes without risking data corruption or user disruption.
Understanding Maintenance Mode
Maintenance mode in WordPress is designed to prevent any changes to your site while updates are being performed. This is particularly useful when updating plugins or migrating your website. When activated, maintenance mode displays a simple HTML page to visitors and returns a status code of 503, effectively halting any theme or plugin activities. This means no new content can be submitted, and no changes can be made until maintenance mode is deactivated.
Why Use Maintenance Mode?
Using the native maintenance mode feature is beneficial for several reasons:
- Control: By using the built-in functionality instead of a third-party plugin, you maintain complete control over your site during this process.
- Efficiency: The native method ensures that all WordPress processes are properly disabled, leading to faster load times and reduced resource usage.
- Environmental Impact: A leaner operation consumes less electricity, contributing to a greener hosting solution.
When to Enable Maintenance Mode
There are various scenarios where enabling maintenance mode is a smart choice:
- Server Migration: When transferring your site to a new server, maintenance mode ensures that the site is copied in its current state, preventing any discrepancies.
- Plugin Updates: Updating plugins without maintenance mode can lead to database overloads, especially on high-traffic sites where simultaneous changes may occur.
How to Enable Maintenance Mode
Enabling maintenance mode can be done in a couple of straightforward ways: via SSH or SFTP. Below is a guide for both methods.
Using SSH
- Log into your site: Access your server using SSH.
- Navigate to your webroot: Typically, this is done with the command:
cd ~/public/
. - Activate maintenance mode: Run the command
wp maintenance-mode activate
. - Deactivate maintenance mode: Once your work is completed, you can disable it by using
wp maintenance-mode deactivate
.
Using SFTP
- Connect via SFTP: Use a client like FileZilla to access your site.
- Locate your webroot: Navigate to the
~/public/
directory. - Create a maintenance file: Right-click to create a file named
.maintenance
and edit it. - Add the PHP code: Insert the following line into the file:
<?php $upgrading = time(); ?>
. - Save and activate: Save your changes to enable maintenance mode. To deactivate, simply delete the
.maintenance
file.
Enabling maintenance mode is a straightforward process that can save you significant headaches down the line, especially during critical updates or migrations. It’s a best practice for anyone looking to manage their WordPress site effectively.