Migrating a WordPress site to Google Cloud Platform (GCP) offers numerous benefits including improved performance, scalability, and reliability. In this comprehensive guide, I’ll walk you through on how to migrate WordPress to GCP using WordOps and EasyEngine, with special attention to sites created with the --wpredis
flag. This guide works whether you’re migrating from a traditional hosting provider to GCP, or between GCP instances. It also covers migrations between WordOps and EasyEngine setups, giving you flexibility regardless of your current configuration. I have outlined few migration scenarios like WordPress traditional server to GCP, WordOps to GCP and EasyEngine to GCP server.
This guide covers several migration scenarios:
Let’s begin with the migration process itself.
Before diving into the migration process, there are a few GCP-specific steps to consider:
For security, it’s best to restrict SSH access:
key-based authentication
onlyFor production WordPress sites, a static IP is highly recommended:
Now, let’s proceed with the migration steps.
ssh [email protected]
cd /var/www/blackmoreops.com/htdocs
sudo wp db export --allow-root
If WP-CLI isn’t installed, install it with:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp
ssh [email protected]
sudo apt-get update && sudo apt-get dist-upgrade -y && sudo apt-get autoremove --purge -y && sudo apt-get autoclean
Might want to restart here to complete any pending steps.
sudo reboot
sudo apt install btop vim dnsutils -y
wget -qO wo wops.cc && sudo bash wo
You might want to install the whole WordOps stack but I found it’s mostly not necessary in reliable hosting provider like GCP.
sudo wo stack install
wget -qO ee rt.cx/ee4 && sudo bash ee sudo ee stack install
I found that by creating an empty site that creates Databse and folder structure, it’s best wastes less resources. We will migrate the Wordpress and contents from old server to new server in next steps.
sudo wo site create blackmoreops.com --wpredis --vhostonly
sudo ee site create blackmoreops.com --type=wp --cache
If you are using password (not SSH keys) then Step is not required.
ssh-keygen -t ed25519
Press Enter to accept the default location.
If you already have SSH keys you’d like to use:
mkdir -p ~/.ssh chmod 700 ~/.ssh
scp ~/.ssh/id_ed25519* [email protected]:~/.ssh/
vi ~/.ssh/id_ed25519 # Paste your private key vi ~/.ssh/id_ed25519.pub # Paste your public key
id_rsa
file in ~/.ssh
folder and set correct permission:
vi id_rsa # Paste your RSA Public key in New Server chmod 600 ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_ed25519 chmod 644 ~/.ssh/id_ed25519.pub
ssh-copy-id [email protected]
Try logging into the old server without a password:
ssh [email protected]
Create or edit ~/.ssh/config
on the new server:
Host OLD-SRV Hostname 166.70.200.19 User ubuntu
Now you can connect using: ssh OLD-SRV
I wrote bunch of guides on SSH, RSYNC issues while working on this. They are documented in the following guides.
sudo rsync -avzh --progress --ignore-existing \ [email protected]:/var/www/blackmoreops.com/htdocs/ \ /var/www/blackmoreops.com/htdocs/
If you’ve set up the SSH alias:
sudo rsync -avzh --progress --ignore-existing \ OLD-SRV:/var/www/blackmoreops.com/htdocs/ \ /var/www/blackmoreops.com/htdocs/
If you want to specify which SSH key to use (useful if you have multiple keys e.g. I am using id_rsa
here):
sudo rsync -avzh --progress --ignore-existing -e "ssh -i /home/ubuntu/.ssh/id_rsa" \ [email protected]:/var/www/blackmoreops.com/htdocs/ \ /var/www/blackmoreops.com/htdocs/
If you run into permsission issues, then simply copy remote files into your home folder then move them to correct location.
cd mkdir htdocs cd htdocs/ mkdir blackmoreops.com cd blackmoreops.com/ sudo rsync -avzh --progress --ignore-existing -e "ssh -i /home/ubuntu/.ssh/id_rsa" [email protected]:/var/www/blackmoreops.com/htdocs/* . sudo mv -f * /var/www/blackmoreops.com/htdocs/ cd /var/www/blackmoreops.com/htdocs/
This step varies depending on the setup of your source and destination servers. Here are the most common scenarios:
If both your old and new servers are using WordOps, the wp-config.php file should already be properly configured in the site root directory on the new server.
WordOps places the main configuration file at /var/www/blackmoreops.com/wp-config.php
, not in the htdocs directory. You should check if the rsync process inadvertently copied a wp-config.php file to the htdocs directory, and if so, remove it:
sudo rm -f /var/www/blackmoreops.com/htdocs/wp-config.php
This ensures that the WordPress installation will use the wp-config.php file at /var/www/blackmoreops.com/wp-config.php
, which was correctly set up when you created the site with WordOps.
If your old server was using EasyEngine v3 and the new one is using WordOps, the location of wp-config.php is different. In EasyEngine, it might have been in the htdocs directory.
If wp-config.php was transferred during the rsync process, you should remove or rename it:
sudo mv /var/www/blackmoreops.com/htdocs/wp-config.php /var/www/blackmoreops.com/wp-config.php.bak
This ensures WordOps uses its own wp-config.php file with the correct database credentials.
If your old server was using WordOps and your new GCP server is using EasyEngine v4, the directory structure is different:
/opt/easyengine/sites/blackmoreops.com/
Handle the configuration by:
# Remove any copied wp-config.php sudo rm -f /opt/easyengine/sites/blackmoreops.com/app/wp-config.php # EasyEngine v4 automatically generates this file in the correct location
If migrating from EasyEngine v3 to v4:
# The directory structures differ significantly sudo rm -f /opt/easyengine/sites/blackmoreops.com/app/wp-config.php # Make sure you've imported the database properly sudo ee site update blackmoreops.com
Navigate to the site directory and import the database:
cd /var/www/blackmoreops.com/htdocs sudo wp db import blackmoreops_com-*.sql --allow-root
Here’s another guide in case you’re creating the entire DB manually or importing it from a SQLdump that’s different to wp DB command
Clean up by removing the SQL dump file:
sudo rm blackmoreops_com-*.sql
If your site was secured with Let’s Encrypt and you’re using WordOps:
sudo wo site update blackmoreops.com -le
If you’re using EasyEngine v4:
sudo ee site ssl blackmoreops.com --le
After migrating your WordPress site to GCP, consider these optimisations:
For a global audience, setting up Cloud CDN can significantly improve performance:
Protect your WordPress site from common attacks:
Ensure your WordPress site is backed up regularly:
gcloud compute disks snapshot DISK_NAME --snapshot-names=SNAPSHOT_NAME --zone=ZONE
sudo crontab -e
Add a line to create daily backups:
0 3 * * * wp db export --allow-root && gsutil cp /var/www/blackmoreops.com/htdocs/blackmoreops_com-*.sql gs://your-backup-bucket/
Tune MySQL for better performance on GCP:
sudo vi /etc/mysql/my.cnf
innodb_buffer_pool_size = 1G innodb_log_file_size = 256M innodb_flush_log_at_trx_commit = 2 innodb_flush_method = O_DIRECT
sudo systemctl restart mysql
If you’re migrating between Google Cloud Platform (GCP) Compute Engine instances, you have additional options:
When both servers are in the same GCP region, you can use internal IP addresses for faster transfers with no egress charges:
sudo rsync -avzh --progress --ignore-existing \ ubuntu@INTERNAL_IP_OF_OLD_SERVER:/var/www/blackmoreops.com/htdocs/ \ /var/www/blackmoreops.com/htdocs/
When servers are in different GCP regions:
sudo rsync -avzh --progress --ignore-existing --compress-level=9 \ [email protected]:/var/www/blackmoreops.com/htdocs/ \ /var/www/blackmoreops.com/htdocs/
By following these steps, you’ll successfully migrate your WordPress site between servers, whether they’re using WordOps or migrating from EasyEngine to WordOps. Have you successfully migrated a WordPress site? Share your experience in the comments below or leave a comment if you have any questions.
That’s it! Enjoy