Posted on

All-in-One WP Migration plugin can be used to perform the migration, but the plugin is not stable when uploading the files to the new server. Today I will introduce a much stable way.

If you are familiar with web hosting with WordPress, you should know that there are 2 major parts, one is the My SQL database and the other is the WordPress PHP scripts under the /var/www/html directory. So to migrate a WordPress blog is basically to migrate these 2 things.

Set up WordPress

Firstly follow either one of the following instructions to set up WordPress framework on Ubuntu 18.04 LTS.

Chinese Version: https://fenghe.us/setup-wordpress-on-ubuntu-18-04/

English Version: https://thishosting.rocks/install-wordpress-ubuntu/

Make sure that the site works when you enter the http://<the ip address of the vps>/ in the browser before the SSL Certificate installation step.

Migrate the Database

On the old server, suppose that your database name is called wordpress by default.

$ mysqldump -u root -p wordpress > wordpress.sql

# fenghe.us should be replaced by your own server IP address
# you will need to enter the root password
$ scp -P 22 wordpress.sql [email protected]:/tmp/

On the new server,

$ mysql -u root -p wordpress < /tmp/wordpress.sql

Note that the ssh port for the new server may not be 22, so if it’s in that case, you should apply the -P option.



Apply the old PHP Configurations

On the new server

$ mv /etc/php/7.2/fpm/php.ini /etc/php/7.2/fpm/php.ini.old

On the old server

$ scp -P 22 /etc/php/7.2/fpm/php.ini [email protected]<new server ip>:/etc/php/7.2/fpm

Migrate the Customized WordPress Framework

On the old server,

$ cd /var/www/
$ sudo apt-get install zip
$ zip -r html.zip html

# you will need to enter the root password again
$ scp -P 22 html.zip [email protected]:/var/www/

On the new server,

$ cd /var/www/
$ sudo apt-get install unzip
$ mv html html1
$ unzip html.zip

Final Steps

Now, we only need to grant the directory with the proper access rights and restart the web service to enable all the modifications we made.

$ chown -R www-data:www-data /var/www/html/
$ chmod -R 755 /var/www/html/
$ systemctl restart nginx.service
$ systemctl restart php7.2-fpm.service

References

  1. https://thishosting.rocks/install-wordpress-ubuntu/
  2. https://fenghe.us/setup-wordpress-on-ubuntu-18-04/
  3. https://www.digitalocean.com/community/tutorials/how-to-migrate-a-mysql-database-between-two-servers

Leave a Reply

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