User Tools

Site Tools


computing:migratewp

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
computing:migratewp [2019/12/30 02:37] oemb1905computing:migratewp [2022/09/03 23:11] (current) oemb1905
Line 11: Line 11:
 ------------------------------------------- -------------------------------------------
  
-This tutorial is designed to step one through how to migrate a self-hosted Word Press site manually Firstcompletely set up LAMP and TLS and DNS, etc., before you begin migration, and review [[https://jonathanhaack.com/dokuwiki/doku.php?id=computing:apachesurvival|Apache Survival]] if you are unclear on how to do that Nowonce that is set up, authenticate as root on the //old host// and backup your entire database (thanks to @jjscha for this mysqldump syntax):+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 instanceIn my caseI have cron jobs that run mysqldump nightly as follows:
  
   sudo -i   sudo -i
Line 29: Line 29:
   --routines          \   --routines          \
   > mysqldump-all-databases.sql   > mysqldump-all-databases.sql
 +  
 +But if you don't have that, then just make a backup of the database on the source host as follows:
  
-Use scp to get the file to the new host:+  mysqldump -u root -p --all-databases > all_databases.sql
      
-  sudo scp mysqldump-all-databases.sql user@newhostorip.com:+Once that's done, send the ''.sql'' file over to the target host as follows:
      
-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.  Make sure the name you pick is unique and was not present in the database backup and/or a restricted user name. +  scp all_databases.sql root@targethost.com:
- +
-  CREATE DATABASE newdatabase DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; +
-  GRANT ALL ON newdatabase.* TO 'newdatabaseuser'@'localhost' IDENTIFIED BY 'temporarypassword'; +
-  FLUSH PRIVILEGES; +
-  EXIT; +
-  CREATE USER 'newdatabaseuser'@'%' IDENTIFIED BY 'temporarypassword'; +
-  GRANT ALL PRIVILEGES ON *.* TO 'newdatabaseuser'@'%' WITH GRANT OPTION;+
      
-Now, you need to create databases and grant privileges to the surrogate user for each of them.  You do this as follows:+Now, ssh into the target host and import the databases as follows:
  
-  CREATE DATABASE restoreddb1 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; +  mysql -u root -p < /root/all_databases.sql
-  GRANT ALL ON restoreddb1.* TO 'newdatabaseuser'@'localhost' IDENTIFIED BY 'temporarypassword'; +
-   +
-If there are others, then repeat the commands above for each one, replacing restoreddb1 with the name of the databases you are importing and bringing in.  Now, time to import that database into the new host:+
  
-  mysql -u newdatabaseuser -h localhost -p --database=newdatabase < /path/to/backup-databases.sql+After the database is migrated, simply copy all the files from web root for the instance over to the new hostEnsure that permissions, configuration files, certificates, etc., are appropriately configured, and then reboot. If any databases came over, but you no longer need them, you can drop them and the users as follows:
  
-Once it finishes, log into the mysql command mode and verify the original databases made it over:+    DROP DATABASE olddb; 
 +    DROP USER 'olddbuser'@'localhost';
  
-  sudo mysql -u user -p +In cases of large databases, you might get an error that the shell lost connection to the database or that it vanished, etc. In that case, adjust your packet and timeout settings:
-  > SHOW DATABASES; +
-  > EXIT+
  
-If possibly, run this command on both machines, and the output should be identical.  Now, it is time to migrate the website //files// over to the new host:+  nano /etc/mysql/mariadb.conf.d/50-server.cnf 
 +  <wait_timeout = 28800> 
 +  <interactive_timeout = 28800> 
 +  <max_allowed_packet=2G>
  
-  sudo scp -r /var/www/website.com/public_html user@newhostorip.com:/var/www/newwebsite.com/ + --- //[[jonathan@haacksnetworking.org|oemb1905]] 2022/09/03 17:10//
-   +
-Put the files in the appropriate locations, restart the mysql service and reboot.  Lastly, once you verify the original databases made it over and the website is restored and functioning, you can delete the surrogate user and database as follows: +
- +
-    DROP DATABASE newdatabase; +
-    DROP USER 'newdatabaseuser'@'localhost'; +
- +
- --- //[[jonathan@haacksnetworking.com|oemb1905]] 2019/12/30 02:37// +
-  +
computing/migratewp.1577673454.txt.gz · Last modified: 2019/12/30 02:37 by oemb1905