This post is purely for my own benefit to keep a note of wordpress and database migration steps. It will be good for anyone finds useful of those information.
Background
Need to move wordpress and database hosting environment from one to another.
Need a quick and simple way to move around files and data. Less operational overhead.
And most important thing is free. (I know there’s lot wordpress plugin that can do the same but most requires payment)
Steps
WordPress files migration
Backup wordpress folder into one file
[Source Server]#sudo tar -czvf wordpressfolder.tar.gz /var/www/wordpresssomething
Sort out certificate based SSH access to Source Server
[Destination Server]#cp privsshkey.key /home/ubuntu/.ssh/
[Destination Server]#sudo chmod 600 /home/ubuntu/.ssh/privsshkey.key
Copy (SCP) wordpress backup file to the new server
[Destination Sever]#sudo scp -P 22 -i /home/ubuntu/.ssh/privsshkey.key [email protected](Source Server IP)123.123.123.123:/home/ubuntu/wordpressfolder.tar.gz /home/ubuntu/
Extract backup wordpress file to new server
[Destination Server]#sudo tar -xzvf wordpressfolder.tar.gz -C /var/www/
Pay attention to the extracted folder structure and you can move around if the path is not what you expect.
WordPress DB migration
Dump and backup wordpress DB
[Source Server]#sudo mysqldump -u root -p --all-databases > all-databases.sql
If you are running newer version mysql, the commands could be something like this
[Source Server]#sudo mysqldump --opt --all-databases > all-databases.sql
Copy DB backup file to new server
[Destination Sever]#sudo scp -P 22 -i /home/ubuntu/.ssh/privsshkey.key [email protected](Source Server IP)123.123.123.123:/home/ubuntu/all-databases.sql /home/ubuntu/
Import DB backup
[Destination Server]#sudo mysql -u root -p < all-databases.sql
or [Destination Server]#sudo mysql < all-databases.sql
Apache configuration migration
Similar to wordpress folder backup and migration. This time backup /etc/apache2/sites-available
, /etc/apache2/sites-enabled
and /etc/apache2/ssl
(if any)
[Destination Server]#sudo a2ensite xxx.example.com
[Destination Server]#sudo systemctl reload apache2
All Done!
Additional Notes
Because the backup files include wordpress and DB file contains confidential data, please consider encrypting those files if you transferring in an insecure channel. SCP/SFTP with correct configuration should be a secure and good way of transferring those files.
Manual migration per DB
If you prefer not to migration all database in one go, it can be played in this way.
Just list couple commands, not into detailed steps.
sudo mysql
create database wordpressdb;
CREATE USER 'wduser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wduser'@'localhost';
sudo mysql wordpressdb < wordpressdb.sql
Leave a Reply