This post shows students and new users steps to migrate a WordPress website to Google Cloud with limited or no down time. When you have a website built on WordPress that is already functioning on one host or locally, migrating it to another server or host can be tricky for new users.
Website migration is a process. You must follow it in order for a successful migration with limited or no down time. From preparing the new server environment to updating your DNS records to reference the new host, these must be followed accordingly.
Below we’ll go through a step-by-step process in order to perform a successful WordPress site migration from one server to a Google Cloud server.
Before we get started, you might want to learn some of the basics, like registering a domain name, and setting up a Google Cloud server in the cloud.
Some other posts that you may want to read are listed below:
The above post should come in handy when migrating a WordPress site to Google cloud.
Taking inventory of a Linux server before migration
Before migrating to a new server, your first task should be to take an inventory of your current Linux server. You want to make sure that your new server matches what you have on your current server.
These are what you’ll need to gather from your current server:
- Web server and version number
- Database server and version number
- PHP and related modules
- Other servers and services and how they’re configured
If you’re running an Apache web server, use the commands below to find out what version is installed on Ubuntu Linux.
apache2 -v
For more detailed version checks and steps to install specific version of Apache, read the post below:
How to check and install specific Apache version on Ubuntu Linux
If you’re running Nginx web server, then use the commands below to find out what version is install on Ubuntu Linux.
nginx -v
For more detailed version checks and steps to install specific version of Nginx, read the post below:
How to check and install specific Nginx version on Ubuntu Linux
To check what version of PHP is installed and how to install specific version on Ubuntu Linux, read the post below:
How to check and install specific PHP version on Ubuntu Linux
Whether you’re running MySQL or MariaDB, the post below shows you how to find out which version of MySQL or MariaDB running on Ubuntu Linux
How to find what version of MySQL or MariaDB running on Ubuntu Linux
How to set up and connect to your Google Cloud server
Now that you’ve taken inventory of your current server, go and register and set up your Google Cloud server. Once you have registered for a Google Cloud account, you can begin setting up a VM (Compute Engine) to host your WordPress content.
Google Cloud server (Compute Engine) allows users to connect using SSH from the browser window to their virtual machine (VM) instance from within the Google Cloud Console.
SSH from the browser supports the following:
- Web browsers
- Latest version of Google Chrome
- Firefox
- Microsoft Edge
- Microsoft Internet Explorer 11 and later
- Safari 8 and later. Note that Safari in private browser mode is not supported.
- Virtual machine configurations
- All Linux VM images that are natively available in Google Cloud.
No additional software or browser extensions needed. Simply login to Google Cloud Console, and go to Menu ==> Compute Engine ==> VM instances.
In the list of virtual machine instances, click SSH in the row of the instance that you want to connect to.
Alternatively, you can open an SSH connection to an instance by clicking its name and clicking SSH from the instance details page.
A SSH terminal window will open with the Ubuntu Linux instance that was created in the second posts of the series.
You should now be able to run commands in Ubuntu Linux created on Google Cloud server.
Install LAMP or LEMP on new server before migration
Now that you have taken inventory of your current server, and you know how to connect to your Google Cloud server, use the post below to install LAMP or LEMP on your new Google server.
Your goal is to make sure the new Google server has all the servers and packages as the current server. We’ve listed some helpful posts above that you can use to install Apache or Nginx, MySQL or MariaDB or PHP.
Some other posts that you may want to use when installing LAMP or LEMP on Ubuntu Linux.
You can use the posts above to install the same servers and packages you have installed on your current server. If you want to install specific packages on your new server, then use the same posts mentioned above.
Once all the packages are installed, you can then begin transferring content from your current server to the new server.
Configure your new Google server similar to your current server
Prior to migration, you’ll want to make sure your new Google server is almost or exactly like your current server.
Make sure the web server (Apache or Nginx) settings are the on both old and new servers, including the same directory structure, and Virtual Host or Server block content.
- Apache directory: /etc/apache2/
- Nginx directory: /etc/nginx/
Your PHP configuration should also be identical to your current server’s PHP settings. Use the post above to install specific PHP version, as well as all the modules currently installed on your current server.
Your MySQL or MariaDB configurations should also mimic your current server. Validate each file, directory and other data to make sure that your new server is no different from your current server before migration.
- MySQL / MariaDB directory: /etc/mysql/
Once you’ve that done, you can continue with the migration process.
Back up current server data and database before migration
Now that you have installed LAMP or LEMP on your new server, and have configured your new server to be identical or very similar to your current server, it’s time to backup the content on the current server so you can migrate it to the new server.
There are two important data you need to move to the new server. You need WordPress website content and the database content. Back up the website content as well as the content in the database.
At this point, you should stop all changes on your current server before backing it up since you won’t want new changes added after backing up.
To back up WordPress content, log on to your server via SSH if you have access. Once you are on your current server SSH console, run the commands below to back up your WordPress content, usually at this location: /var/www/html/.
A backed up file named current-server-backup.tar will be created with your WordPress content when you run the commands below.
sudo tar -cvf current-server-backup.tar /var/www/html/
Next, back up your database content. You need to use the root account or an account with full access to the database you wish to back up.
To backup all databases on the server, you run the commands below:
sudo mysqldump -u username –p --all-database > all_databases_backup.sql
A file named all_databases_backup.sql should also be created in the current working directory.
You should now have two files: current-server-backup.tar and all_database_backup.sql.
Copy the current server’s content to Google Cloud server
At this point, you should be ready to copy the current server’s content over to your new server. There are many ways to get the tar file and SQL data file to the new server.
You can use the rsync command from the new server by SSHing into it and using a similar command to that shown below (changing the host names as needed).
While connected to your Google Cloud console, run the commands below to connect to your current server and copy over the backed up content.
rsync -avz [email protected]:/home/<username>/all_database_backup.sql rsync -avz [email protected]:/home/<username>/current-server-backup.tar
You could also use scp to securely copy your files, the syntax looks like:
scp [email protected]:/home/<username>/all_database_backup.sql /home/username/ scp [email protected]:/home/<username>/current-server-backup.tar /home/username/
If you can’t get the files using SSH, then you can use the wget command to download the files to your new Google Cloud server.
You must copy the files to the current server web server root directory to be able to use the commands below.
cd ~ wget wget
Once the files are copied to your new server, continue below to extract it and import the database content into your database server.
Restore current server’s content onto Google Cloud server
Now that you have copied over the current’s server content to your new server, run the commands below to extract the archive content, and copy the website content to your html directory similar to what’s configured on your current server.
tar -xvf current-server-content.tar sudo cp -rf /var/www/html/ /var/www/html/
Next, run the commands below to import the database content to your database servers.
sudo mysql -u root -p < all_database_backup.sql
At this point, your Google server should have the current server’s content as well as the database content. Run the commands below to set up the current permissions so that they match the current server.
Validate that all configurations on your current server match that of your new Google Cloud server. Once all have been validated, restart your webserver.
sudo systemctl restart nginx sudo systemctl restart apache2
If you get an error, make sure to resolve the error.
Update your DNS and point your domain to your new Google server IP address
Prior to going live and updating your DNS A records to point to your new server, you can test locally by editing your /etc/hosts or hosts file on Windows. Point your domain to your new IP address, and browse to it. If it appears with no error, then you can update your public DNS A record to point to your new Google server IP address.
Once your local test is successful, go to your DNS provider portal, login and update the DNS A record to point to your new server IP address.
If everything works, you can continue fine-tuning your new server to make sure all is configured correctly.
That should do it!
Conclusion:
This post showed you how to migrate a WordPress website to Google Cloud server. If you find any error above or have something to add, please use the comment form below.