Sunday, October 1, 2023

WordPress - How to Migrate Site to new Server

 Scenario:  Migrate WordPress Sites from Ubuntu LAMP Server to a new Host

For years I have hosted some family WordPress sites on a Cloud server.  Needing to both upgrade it and move it to a new Cloud location, necessitated transferring the websites to a new host and not simply migrating the server.  There were multiple factors that led to this approach and I'm sure several ways to solve this problem.  However, I have needed to determine a good way to back up WordPress sites and a documented method of migrating test sites to production.

What I found that worked for me was the following steps and using the plugin (Duplicator).  I have now migrated numerous sites using this method both from on-prem servers and from cloud to cloud.

STEPS:

  • Setup new location (LAMP Server)

  • Create a new database and database user (on the new server) that will be used for the website.  

    • Does not need to match the old website/database. Data will be imported into the new database.

    • Database Config
      • $ sudo mysql -u root

      • Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

      • mysql> CREATE DATABASE newdatabasename;

      • mysql> CREATE USER newdatabaseuser@localhost IDENTIFIED BY '<your-password>';

      • mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER

      •     -> ON newdatabasename.*

      •     -> TO newdatabaseuser@localhost;

      • I ran into problems with one import and it required that I "GRANT ALL" to the newdatabaseuser for the full import of the website to work.

      • mysql> FLUSH PRIVILEGES;

      • mysql> quit


  • Create a new folder in the new location (/var/www/newsite)

  • Install “Duplicator” Plugin on the current site

    • Run Duplicator and create a package

    • On Some older Mysql installations, I had to change the following setting

      • Duplicator -> Settings -> Packages -> SQL Mode -> 

        • Change from Mysqldump to PHPcode

  • Download both the .zip and installer.php files to my local machine

  • SCP -> New Server/Location

    • You can use whatever method you want to move the files from the server to the new host/server.
  • Copy both files to the new directory on the new server

  • Unzip .zip file or when you run the the Installer.php file, it will ask for the .zip file and unzip it as part of the installation process.

  • Change ownership & permissions on the new location (before running the installer.php)

    • chown -R www-data:www-data /var/www/newsitelocation

    • chmod -R 755 /var/www/newsitelocation

  • Run Installer (installer.php)

No comments: