fbpx
Skip to content

How to migrate your wordpress site manually – Better and faster

WordPress is one of the most popular content management systems in the world.

WordPress is being used to build a large number of websites. Unfortunately, you might need to transfer your WordPress site to a different host or domain sometimes.

I’m not going to go into details on what is migration or hosting. I’ll get right to how to transfer the site the best way possible

This method may sound complex but trust me, this is one the easiest way to migrate sites faster.

Before we begin, here are a couple of requirements that you will need. 

  • SSH Access (user level or root level, both works fine. I recommend user level)
  • WordPress Installation path directory location. (find here: WP > tools > site health > info > Directory & sizes)
  • Database records of the both servers. (For existing installation, you can find on wp-config.php file and for new server, I suggest creating new database + user)
  • Don’t update new server ns records or IP until the migration.

NOTE: It is always a bad idea to keep compressed or sql files in the public path directory; recommended to remove these compressed or sql files as soon as the migration is completed.

Here is the strategy we will be using:

  • Export database in the wordpress installation directory
  • Compress WordPress installation directory.
  • Download the compressed file on the new server.
  • Import Database.
  • Update new database credentials on wp-config.php file.

To get started with this migration process, make sure you have all requirements that you need to get started.

Start with navigating to your WordPress installation directory with the following command:

cd /home/username/public_html

Replace the directory path to your WordPress. (find here: WP > tools > site health > info > Directory & sizes)

Export Database:

The following command line will be used to export the database to a directory installation. We’re exporting this database to the WordPress directory installation because it will be useful in the next step. We wouldn’t have to download the SQL database file separately, it will be compressed along with other files.

Run the following command:

mysqldump --no-tablespaces -u current_database_username -p current_database_name > exported_file_name.sql

Replace these respectively

  • current_database_username: Your current WordPress database username (wp-config.php file – DB_USER)
  • current_database_name: Your current WordPress database name (wp-config.php file – DB_NAME)
  • exported_file_name: You can change this to anything,

As soon as you run the above command, you will be asked to enter the password, paste your database user password. (wp-config.php file – DB_PASSWORD)

Now the exported file will be stored under your WordPress installation directory.

Compress WordPress installation directory:

Now compress all files under the WordPress installation directory with the following command:

tar -zcvf archive-name.tar.gz *

Replace these respectively

  • archive-name: Your compressed file name, can be anything.
  • * : This would compress all files/folders within the same directiry. please don’t replace this to anything as long as you are on the wordpress installation directory.

Now, you should be having a compressed file.

Download the compressed file on the new server:

Now access your new server SSH and navigate to the directory path where you want to migrate the site files to (domain directory)

cd /home/username/new-wordpress

Download the compressed file using the following command:

wget domain.com/archive-name.tar.gz

Replace these respectively

  • domain.com: Replace this with your domain name.
  • archive-name: compressed file name that we used in the previous step.

Now we extract the downloaded compressed file with the following command:

tar -xf archive-name.tar.gz

Replace these respectively

  • archive-name: compressed file name that we used in the previous step.

Import Database:

If you remember, We exported the database SQL file before compressing files. you should be having the SQL file in your new server when you extract the archive file in the previous step.

I’m presuming you’ve already created a new database and database user on your new server;

Now run the following command to import the database:

mysql -u new_database_user -p new_database_name < exported_file_name.sql

Replace these respectively

  • new_database_user: Your new database user on the new server that you are migrating to.
  • new_database_name: Your new database name on the new server that you are migrating to.
  • exported_file_name: Exported databse sql file name, if you changed the file name. you can replace it.

When you run the above command, you’ll be asked to enter the password. paste your new database user password.

Update new database credentials on wp-config.php file:

Open your wp-config.php file and update the new database name, user and password. You are done. the site should be working just fine if you point your domain A records to the new server IP or new ns records.

That’s all. If you have any questions, ask in the comment sections.

Answering a couple of errors you may encounter you migrate sites:

Sub-pages or blog links not working except home page: Save permalink structure, it should solve the problem.

Changing URL: Above steps explain how to migrate between different servers if you’re looking to change the domain name as well. then run the following SQL query in your new server.

New server >> PHPMyAdmin >> Click on database >> sql query

UPDATE wp_options SET option_value = replace(option_value, 'oldurl.com', 'newurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';UPDATE wp_posts SET guid = replace(guid, 'oldurl.com','newurl.com');UPDATE wp_posts SET post_content = replace(post_content, 'oldurl.com', 'newurl.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'oldurl.com','newurl.com');

Leave a Reply

Your email address will not be published. Required fields are marked *