How to migrate wordpress site to new domain
Migrating a WordPress site to a new domain can be a bit of a process, but it's definitely doable. Here's a step-by-step guide to help you through the process:
Before you start:
- Backup your site: Make sure to backup your WordPress site, including the database and files, before making any changes. This will ensure that you can restore your site if anything goes wrong during the migration process.
- Update your DNS: Update your DNS settings to point to the new domain. This may take some time to propagate, so be patient.
Step 1: Update your WordPress configuration
-
Update the
wp-config.php
file: Open thewp-config.php
file in a text editor and update theDB_HOST
,DB_USER
, andDB_PASSWORD
variables to reflect the new database host, username, and password. -
Update the
wp_options
table: Run the following SQL query to update thewp_options
table with the new domain:UPDATE wp_options SET option_value = REPLACE(option_value, 'old-domain.com', 'new-domain.com') WHERE option_name = 'site_url' OR option_name = 'home_url';
Step 2: Update your theme and plugins
-
Update your theme: Update your theme to ensure that it's compatible with the new domain. You may need to update the theme's
style.css
file to reflect the new domain. -
Update your plugins: Update your plugins to ensure that they're compatible with the new domain. You may need to update the plugin's settings or configuration files to reflect the new domain.
Step 3: Update your database
-
Export your database: Export your WordPress database using phpMyAdmin or a similar tool.
-
Update the database: Update the database by running the following SQL queries:
UPDATE wp_posts SET post_content = REPLACE(post_content, 'old-domain.com', 'new-domain.com'); UPDATE wp_posts SET post_title = REPLACE(post_title, 'old-domain.com', 'new-domain.com'); UPDATE wp_options SET option_value = REPLACE(option_value, 'old-domain.com', 'new-domain.com');
Step 4: Update your files
-
Update your files: Update your WordPress files to reflect the new domain. You'll need to update the following files:
wp-config.php
wp-content/themes/your-theme/style.css
(if you're using a custom theme)wp-content/plugins/your-plugin/plugin-file.php
(if you're using a custom plugin)
-
Update your images: Update your images by running the following command:
find. -type f -name "*.jpg" -o -name "*.png" -o -name "*.gif" -exec sed -i 's/old-domain.com/new-domain.com/g' {} \;
Step 5: Update your DNS
-
Update your DNS: Update your DNS settings to point to the new domain. This may take some time to propagate, so be patient.
Step 6: Test your site
- Test your site: Test your site to ensure that everything is working as expected. Check that all links, images, and other assets are loading correctly.
Additional tips:
- Use a migration plugin: Consider using a migration plugin like Duplicator or UpdraftPlus to simplify the migration process.
- Test your site in staging: Test your site in a staging environment before making the changes live to ensure that everything is working as expected.
- Be patient: Migrating a WordPress site to a new domain can take some time, so be patient and don't rush the process.