The idea here is to move a wordpress site from one server site to another.
Step 1. Information needed before starting !!
1. ip address of existing site, say for this example, “18.104.22.168”.
2. ip address of new site, say “22.214.171.124”.
3. normal user ( say user1 ) and root user password for existing site.
4. normal user ( say user2 ) and root user password for new site.
5. Name of wordpress database on existing site, say “database1”.
6. Name of wordpress database on new site, say “database2”.
7. User name and password for accessing the wordpress database on existing site, say “dbuser1”.
Note: The user name and password for accessing the wordpress database on the new site, will still be dbuser1, as it is copied over too.
8. Directory name of wordpress on existing site. say /var/www/wordpress1.
9. Directory name of wordpress on new site, say /usr/local/blogs/wordpress1 ( as we will install more than one wordpress site, starting with this one ).
10. Password for user ‘root’ on the new database.
11. On the existing site, where to store the back ups: /var/local
12. On the new site, where to first load the new wordpress source: /usr/local/src
Note: good idea to print this list off with all the addresses, user names, passwords and database names, for easy reference. Someone stole my phone on a train once, so I also recommend not ever putting passwords in phones.
Step 2. Backup the existing site.
(a) Backup the existing wordpress database.
# ssh email@example.com # su # cd /var/local ( a place to hold the two backup files ) # mysqldump -u dbuser1 -p database1 > database-backup.sql # tar zcf database-backup.sql.tar.gz database-backup.sql
(b) back up the wordpress files.
# cd /var/www # tar czf /var/local/wordpress-files.tar.gz wordpress1
Step 3. Down load the latest wordpress version onto the new site, say at /usr/local/src.
# cd /usr/local/src # wget https://wordpress.org/latest.tar.gz # gzip -d latest.tar.gz # tar xvf latest.tar
The latest sources will now be in /usr/local/src/wordpress, but we do not run them as we will need to merge them with the old version.
Step 4. Copy over the existing wordpress files and database to the new site.
# su firstname.lastname@example.org # su # cd /usr/local/blogs # sftp email@example.com < enter the password for user1 > sftp> cd /var/local sftp> ls ( will list the files in this directory ) sftp> get wordpress-files.tar.gz sftp> get database-backup.sql.tar,gz sftp> bye # ls -la
Note: this list will show that wordpress-files.tar.gz and database-backup.tar.gz have both been completely copied over.
Step 5. Unpack the old wordpress site onto the new site.
# ssh firstname.lastname@example.org # su # cd /usr/local/blogs # ls -la ( should show wordpress-files.tar.gz and database-backup.sql.tar.gz ) # gzip -d wordpress-files.tar,gz # tar xvf wordpress-files.tar Note: there will now be a directory here called “wordpress1” ( ie /usr/local/blogs/wordpress1 ). # chown -R apache wordpress1 # chgrp -R apache wordpress1
Step 6. Merge the latest wordpress source with the exiting site’s version.
That is, replace the old wordpress software that we transferred over with fstp, but keep the data from the previous site.
(a) Firstly, go to the directory where the old wordpress software was copied too ( making sure we are on the new server and in the right directory ), and then delete the old wordpress software that we will replace.
# ssh email@example.com # su # cd /usr/loca/blogs/wordpress1/wp-includes # rm -r * # cd /usr/local/blogs/wordpress1/wp-admin # rm -r *
(b) copy over some ( but not all ) of the new wordpress software ( now located at /usr/local/src ) into our existing wordpress. Careful not to delete any existing content, of course.
# cd /usr/local/blogs/wordpress1 # cp -R /usr/local/src/wordpress/wp-includes/* wp-includes # cp -R /usr/local/src/wordpress/wp-admin/* wp-admin # cp -R /usr/local/src/wordpress/wp-content/* wp-content Also, copy over the newer php files in the main directory. # cp /usr/local/src/wordpress/*.php .
Step 7. Load the existing backed up wordpress database into our new site.
# ssh firstname.lastname@example.org # su # systemctl start mysql ( in case it is not already running ) # cd /var/local/blogs ( where we copied over the backed up database ) # gzip -d database-backup.sql.tar.gz # tar xf database-backup.sql.tar
Create the new database and a new user to access this database.
Note: this new user is different to the user for the wordpress blog. Put another way, this is the user that the wordpress software users to access the database, not the user name we use to log into the wordpress blog.
# mysql -u root -p MariaDB [(none)]> CREATE DATABASE database2; MariaDB [(none)]> GRANT ALL PRIVILEGES ON JHB.* TO 'fred'@'localhost' > IDENTIFIED BY 'new password'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> exit # mysql -u root-p database2 < database-backup.sql Check that the backed up data was loaded. # mysql -u root -p MariaDB [(none)] > show databases; MariaDB [(none)] > use database2; MariaDB [(database2)] > show tables; MariaDB [(database2)] > select * from wp_users; ( the previous wordpress user will be listed ) MariaDB [(datbase2)] > exit
Step 8. Update the apache config file for the new site.
# systemctl status ( will show what is currently running ) # whereis apache2 ( to show hopefully where to find apache ) # /usr/local/apache2/bin/apatchectl -V ( will list where the apache configuration file is located )
For example, adding this to the apache config file:
<VirtualHost 126.96.36.199:80> ServerName our-domain-name.com ServerAdmin webmaster@localhost DocumentRoot /usr/local/blogs/wordpress1 ErrorLog /var/log/apache2/error.log CustomLog /var/log/apache2/our_domain_access.log combined </VirtualHost>
# systemctl reload apache ( restart the web server )
Clear the browser history. Also, take out the domain name from the previous server.
The browser may now display the new wordpress site ( at 188.8.131.52 ).
If errors occur when establishing the database connection, check the wp-conf.php file that was copied over, as “Host” may have changed ( eg 127.0.0.1 instead of localhost ).
Note: permalinks will probably need to be checked ( in wordpress’s dashboard->settings->permalinks and saved ).
In the apache config file, often need to tell apache the default file to display:
DirectoryIndex index.html index.php
© 2017, James Harry Burton. All rights reserved.