There are four major copies of the WordPress moving process.
- Database
- Plugins
- Theme
- Uploaded files such as media files
The method I'm about to show you can also be done with WordPress multisite.
This is written by a Japanese who can't speak English with the help of translation application. Sorry if it's not good.
Every system has its own moving process, but so does WordPress.
Making the development environment out of the production environment.
Making the production environment out of the development environment.
Launching multiple copies of the same system.
System error recovery work.
This is a commentary for smoothing out these situations when encountered. I'll keep it simple.
Building a WordPress environment at the new location
First, prepare the WordPress environment of the destination.
- Web Server
- Database Server (also database creation)
- PHP (when not. often installed if Linux)
- Installation of WordPress
Since this section describes the migration process, the respective installation methods are omitted.
Moving the Database
Create a backup file (.sql) using the WordPress backup plugin or a database backup command such as 'mysqladmin'.
Change database settings
When the database settings change in a new environment, change the configuration information in wp-config.php.
define('DB_NAME', 'db-name');
define('DB_USER', 'db-user');
define('DB_PASSWORD', 'db-password');
/** Here's when you need to change it. Very little to change. */
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
Importing database information
mysql -uuser -ppassword db_name < backup.sql
Restore the database. The above is how to do it with MySQL (MarriaDB).
Change Domain
If the domain you are moving to does not change, skip this section.
Use the WordPress command tool to batch replace all the domains registered in the database.
We will not use SQL bulk replace here.
wp search-replace 'old-domain.com' 'new-domain.com'
When using multisite, the tables in the child sites will not be replaced, so we will add an option.
wp search-replace 'old-domain.com' 'new-domain.com' --network
The '--network' option will also replace the tables in the child sites of the multisite.
For multisite, add the setting to wp-config.php.
define('DOMAIN_CURRENT_SITE', 'new-domain.com');
- Don't use SQL bulk replace.
- For batch replacement, use the WordPress command "wp search-replace".
If you are having trouble with an error
The following error may occur with bulk domain substitution
"Error: Site 'sample.test/' not found. Verify DOMAIN_CURRENT_SITE matches an existing site or use --url=<url> to override."
This error is a data inconsistency that occurs if you specify 'DOMAIN_CURRENT_SITE' in wp-config.php before importing new data into the database.
This happens when importing data from the latest database into a test environment that has already been created.
wp-config.php | New Domain |
Imported data | Old domain |
Modify the command for bulk domain substitution to allow for this to occur.
wp search-replace 'old-domain.com' 'new-domain.com' --url="old-domain.com" --network --path=/home/myuser/html/DocumentRoot
To fix the domain inconsistency, use '--url="old domain"' to force a change in the value of 'DOMAIN_CURRENT_SITE' when importing.
(Keep the value in wp-config.php)
I also added the '--path' option so that the 'wp' command can be executed outside of the WordPress installation directory.
This command can be used for other than multisite, so batch domain changes can be performed with it.
Moving the WordPress environment
Copy backups of plugins, theme source files, uploaded media files, etc. to the new WordPress environment.
Backups are provided by WordPress plugins, so it is recommended to do backups on a regular basis.
Some backup plugins include database backups.
I recommend BackWPup. It can backup plugins, themes, uploaded files including media, and databases.
You can also backup your entire WordPress environment.
Moving plugins
Copy the plugin files in 'DocumentRoot/wp-content/plugins' to the new environment. You can overwrite any plugins that already exist, but to be safe, delete any duplicate plugins in the new environment before copying them.
Next, confirm that the plugins you copied are displayed in the "Installed Plugins" section of the admin panel. After confirming that they are displayed, activate each plugin.
If the database has been moved, the plugin configuration information has also been copied, so that's all there is to it.
Moving the theme
Copy the theme files in 'DocumentRoot/wp-content/themes' to the new environment.
Maybe you have directly written the url domain in your theme file customization. In that case, please change the domain name to match your new environment.
It is not a good idea to write the domain directly; use the functions provided by WordPress.
Moving media files and other uploaded files
Copy the files in 'DocumentRoot/wp-content/uploads' to the new environment.
That's it for the moving process.
Responding to 'Permission denied'
When the moving process is completed successfully and you check the operation, "Permission denied" may occur.
This is caused by a file or directory permission error, such as when a compressed file such as tar.gz is decompressed and then transferred to a new environment.
Backup files are usually compressed using tar.gz or similar, so make sure to extract them on the server in the new environment.
If it still happens, change the permissions of each directory and file to the same permissions as before the move using the 'chmod' command.