Migrating Wordpress is not that a big deal. The only tricky part is if the website changes domain, e.g. from
As general instructions:
Pack up the Wordpress directory using
You have to create a package to transfer over to the new location. To do this navigate inside the main wp directory and use a command like this:
tar -cvfz my_wp_packed.tar .. This means "pack everything here (the
my_wp_packed.tar and compress it". This should result in a
.tar.gz file. Copy it somewhere and keep it aside for now.
Dump the database using
Find the database credentials (
cat wp-config.php inside the wp main directory will show the configuration, among which you will find the credentials) and move to your home directory, then use this command to dump the whole database to a
mysqldump -u my_db_user -pmy_db_password my_wp_database > my_wp_db.sql. Substitute username, pass and database with your data. look out: the password must be attached to the
-p flag, like in the example, no spaces!. Take the resulting
.sql file aside and move to the next step.
Move everything to the new location and unpack the site
The new location could be another directory on the same server, or another server. In the first case, you have just to create the new root (for example with
mkdir /var/www/vhosts/my_new_webroot) and
cd into it. Copy here the
.tar.gz file created in step 1. Then, unzip the website with
tar -xvf my_wp_packed.tar.gz.
If the other location is on another server use
scp to copy it over.
Migrate and import the database
Once you've set up the new database for the website, you are ready to import the
sql. First you have to replace inside the file, which is editable as a text file with
nano, the values of the
home options, found inside the
wp_options table. Just place your new website url in place of the old one.
The location inside the file looks something like this:
(36, 'advanced_edit', '0', 'yes'),
(37, 'comment_max_links', '2', 'yes'),
(38, 'gmt_offset', '0', 'yes'),
(39, 'default_email_category', '1', 'yes'),
(40, 'siteurl', 'https://myoldwebsite.com', 'no'),
(41, 'template', 'mystile', 'yes'),
(42, 'stylesheet', 'mystile', 'yes'),
(43, 'home', 'https://myoldwebsite.com', 'yes'),
Once you did this you are ready to import:
mysql -u my_new_db_user -pmy_new_db_password my_new_database < my_wp_db.sql
And you're done! Do not forget to remove the tar and sql files from the wordpress directory, to avoid anyone from downloading them.