User Tools

Site Tools


computing:migratewp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
computing:migratewp [2019/02/18 05:45] – created oemb1905computing:migratewp [2022/07/31 17:48] oemb1905
Line 11: Line 11:
 ------------------------------------------- -------------------------------------------
  
-This tutorial is designed to step one through how to migrate a self-hosted Word Press site manually Firstauthenticate as root on the //old host// and backup your entire database.+This tutorial is designed to step one through how to migrate a mysql database to another hostThe tutorial is named migratewpbecause I first did this on a WP instance. First, use mysqldump to dump the entire database:
  
   sudo -i   sudo -i
Line 30: Line 30:
   > mysqldump-all-databases.sql   > mysqldump-all-databases.sql
  
-The spacing is optional and thanks to @jjscha for providing a great template to use.  This can and should be used as a backup script.  You can find the latest version [[https://codetalkers.services/oemb1905/hackingclub/blob/master/nixnscripts/backup_mysql.sh|mysql-backup.sh]].  Now that your database is secure, let'import that database into the //new host// as follows:+Use scp to get the file to the new host: 
 +   
 +  sudo scp mysqldump-all-databases.sql user@newhostorip.com: 
 +   
 +Before your import the mysqldump databases into the new database, you need to create what I call a "surrogate" user and database to do the heavy lifting for you first.  You will also grant this surrogate user super privileges.
  
-  mysql -u user -h localhost -p < /path/to/mysqldump-all-databases.sql+  CREATE DATABASE temp; 
 +  CREATE USER tempuser@localhost IDENTIFIED BY 'tempass'; 
 +  GRANT ALL PRIVILEGES ON temp.* to tempuser@localhost IDENTIFIED BY 'tempass'; 
 +  FLUSH PRIVILEGES; 
 +  EXIT;
      
-This will take some time.  Once it finishes, log into the mysql command mode and verify the databases made it over:+Now that you have created a temporary database and database user with full privileges, it is time to import the backup.
  
-  mysql -u user -p+  mysql -u newdatabaseuser -h localhost -p --database=newdatabase < /path/to/backup-databases.sql 
 + 
 +Once it finishes, log into the mysql command mode and verify the original databases made it over: 
 + 
 +  sudo mysql -u user -p
   > SHOW DATABASES;   > SHOW DATABASES;
   > EXIT   > EXIT
  
-Run this command on both machinesand the output should be identical Nowit is time to migrate the website over:+After the database is migratedsimply copy all the files from web root for the instance over to the new hostEnsure that permissions and configuration files are appropriatethen reboot. Once the database is migrated, you can delete the surrogate user and database as follows:
  
-  scp -r /var/www/website.com user@newhost.com: +    DROP DATABASE temp; 
-   +    DROP USER 'tempuser'@'localhost';
-Put the files in the appropriate locations, obviously make sure you set up TLS again if needed and check file permissions for the directories, but that should be it.  Your WP website is now on the new host.  Of course, also make appropriate DNS / port forwarding adjustments so that the new website is accessible.+
  
- --- //[[netcmnd@jonathanhaack.com|oemb1905]] 2019/02/17 22:06// +That should be all there is to it! 
-   + 
-  + --- //[[jonathan@haacksnetworking.org|oemb1905]] 2022/07/31 11:42//
computing/migratewp.txt · Last modified: 2022/09/03 23:11 by oemb1905