WORDPRESS MIGRATION

There are lots of reasons to move your WordPress site, better high speed hosting, better support and security monitoring, moving to a High Availability model and need a second copy of it running or just plain cost.

Steps to achieve wordpress migration

  1. Package up your site’s files using a tool such as “tar”.
  2. Dump the database image to a file which also includes the commands needed to recreate the database tables.
  3. Transfer the files to the new host using  rsync.
  4. On the new host, reverse the “tar” package back to files in the correct location.
  5. Create the new database and Import the database dump file.
  6. Change the WordPress config for the new database user name and password if needed.
  7. Configure the web server to host the site.

 Change Localhost to point to the new server

Packaging up your site

First log into your web site via an SSH application and navigate to your web server root directory. My server stores website files in /home/reviewdo/public_html    

To package my files I will use the unix utility “tar” to create an archive of my site ready to transfer.

tar -cvzf file.tar /path/to/documentroot

Enter in to the document root

#cd /home/reviewdo/public_html

Next we need to dump our database tables, to do this we need the Database name, Database User Name and Password. wp-config.php contains the details about the database

#cat wp-config.php | grep DB

We should get the output as shown bellow

define(‘DB_NAME’, ‘wpdatabase’);

define(‘DB_USER’, ‘wpuser’);

define(‘DB_PASSWORD’, ‘password’);

define(‘DB_HOST’, ‘localhost’);

define(‘DB_CHARSET’, ‘utf8mb4’);

define(‘DB_COLLATE’, ”);

Once the values are found we can backup the database eg: wpdatabase into a File with.sql extension using mysqldump facility

mysqldump -u wpuser -ppassword wpdatabase > data.sql

where the data.sql contains the wordpress sql statements. we need this along with file.tar on the new server.

Migration

Log into Destination server

#ssh [email protected]

Once the files have arrived on the new server, you need to extract the tar file into the new directory:

#mkdir /var/www/html/yoursite

#cd /var/www/html/yoursite

#tar -xvf file.tar

For creation of  new Domain we need to replace the old domain with new domain using replacement tool called “sed” streameditor

#sed -i ‘s/oldurl/newurl/g’ /path/to/mysqldb.sql

Creation of new database

#mysql -u root -ppassword

Create database databasename;

Create user ‘databaseuser’@’localhost’ identified by ‘databasepasswd’;

GRANT ALL PRIVILEGES ON databasename.* TO ‘databaseuser’@’localhost’;

FLUSH PRIVILIGES;

exit;

Copy the mysql.sql file to newly created database

#mysql -u root -p password database < /pathto/mysql.db

Web Server configuration

The web server will require a configuration file for the new site, this file will define the Document Root directory, the URL via the ServerName. My web site configuration files are located in /etc/apache2/sites-available/yoursite.conf

#vi /etc/apache2/sites-available/yoursite.conf

<VirtualHost *:80>

    ServerAdmin [email protected]

    ServerName mynewsite.com

    DocumentRoot /var/www/html/yoursite/

    <Directory /var/www/html/yoursite>

        AllowOverRide All

    </Directory>

</VirtualHost>

To enable the new site configurationfile add

a2ensite yoursite.conf

Add Entry in Hosts file

To run the website in your local machine

#sudo vi /etc/hosts

ip address : mynewsite.com

Restart Services

#systemctl restart  httpd

#systemctl restart  mysql

Open Webbrowser and type

http:/mynewsite.com

Conclusion

You have successfully migrated wordpress website

You May Also Like

About the Author: admin

Leave a Reply

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