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.
Table of Contents
Migration Scenarios
This guide covers several migration scenarios:
- Traditional hosting to GCP
- Migrating from a non-GCP server to a GCP Compute Engine instance
- Between GCP instances in the same region
- Using internal network for faster, cost-effective transfers
- Between GCP instances in different regions
- Handling cross-region transfers effectively
- WordPress setup variations
- WordOps to WordOps migration
- EasyEngine to WordOps migration
- WordOps to EasyEngine migration
Let’s begin with the migration process itself.
GCP-Specific Setup
Before diving into the migration process, there are a few GCP-specific steps to consider:
Creating Your GCP Compute Engine Instance
- Log in to the Google Cloud Console
- Create a new Compute Engine instance:
- Select an appropriate machine type (e2-medium is a good starting point for most WordPress sites)
- Choose Ubuntu 24.04.2 LTS or later LTS release as your boot disk
- Allow HTTP and HTTPS traffic in the firewall settings
- Consider selecting Premium tier networking for better performance
- If cost is a concern, you can use the Spot VM option for significant savings
- Once your instance is running, note both its external IP and internal IP (if you plan to migrate between GCP instances)
Setting Up Proper Firewall Rules
For security, it’s best to restrict SSH access:
- Navigate to VPC Network > Firewall in the GCP Console
- Create a new firewall rule to restrict SSH (port 22) to only your IP address
- Consider setting up a more secure SSH configuration with
key-based authentication
only
Setting Up a Static IP (Recommended)
For production WordPress sites, a static IP is highly recommended:
- Go to VPC Network > External IP addresses
- Change the IP address type from Ephemeral to Static
- Give your static IP a name for easier reference
Now, let’s proceed with the migration steps.
Step 1: Prepare the Source Server
Export the WordPress Database
- SSH into your old server:
ssh ubuntu@166.70.200.19
- Navigate to your site directory:
cd /var/www/blackmoreops.com/htdocs
- Export the database using WP-CLI:
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
Step 2: Set Up the Destination GCP Server
SSH into your new GCP server:
ssh ubuntu@201.21.71.189
Update the Server
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
Install WordPress Management Tool
Install basic Utils
sudo apt install btop vim dnsutils -y
Option 1: Install WordOps
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
Option 2: Install EasyEngine v4
wget -qO ee rt.cx/ee4 && sudo bash ee sudo ee stack install
Create an Empty WordPress Site
With WordOps:
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
With EasyEngine v4:
sudo ee site create blackmoreops.com --type=wp --cache
Step 3: Set Up Password-less SSH Between Servers (Optional)
If you are using password (not SSH keys) then Step is not required.
Set Up SSH Keys on the new server
Option 1: Generate New SSH Keys
ssh-keygen -t ed25519
Press Enter to accept the default location.
Option 2: Import Existing SSH Keys
If you already have SSH keys you’d like to use:
- Create the .ssh directory if it doesn’t exist:
mkdir -p ~/.ssh chmod 700 ~/.ssh
- Copy your existing private and public keys to the new server:
- Using SCP:
scp ~/.ssh/id_ed25519* username@201.21.71.189:~/.ssh/
- Or manually by copying the contents of your existing keys and pasting them into the appropriate files on the new server:
vi ~/.ssh/id_ed25519 # Paste your private key vi ~/.ssh/id_ed25519.pub # Paste your public key
- If you’rem using RSA key’s simply create an
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
- Set proper permissions:
chmod 600 ~/.ssh/id_ed25519 chmod 644 ~/.ssh/id_ed25519.pub
Add Your Public Key to the old server
ssh-copy-id ubuntu@166.70.200.19
Test the SSH Connection
Try logging into the old server without a password:
ssh ubuntu@166.70.200.19
Set Up SSH Aliases (Optional)
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.
- SSH Key Management Best Practices
- Troubleshooting rsync SSH Authentication Issues
- Converting PuTTY SSH Keys for Ubuntu
Step 4: Transfer Files Between Servers
Using rsync with the Ubuntu user
sudo rsync -avzh --progress --ignore-existing \ ubuntu@166.70.200.19:/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" \ ubuntu@166.70.200.19:/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" ubuntu@166.70.200.19:/var/www/blackmoreops.com/htdocs/* . sudo mv -f * /var/www/blackmoreops.com/htdocs/ cd /var/www/blackmoreops.com/htdocs/
Step 5: Handle the wp-config.php File
This step varies depending on the setup of your source and destination servers. Here are the most common scenarios:
Option 1: WordOps to WordOps Migration
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.
Option 2: EasyEngine to WordOps Migration
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.
Option 3: WordOps to EasyEngine v4 Migration
If your old server was using WordOps and your new GCP server is using EasyEngine v4, the directory structure is different:
- EasyEngine v4 typically stores sites in
/opt/easyengine/sites/blackmoreops.com/
- The database credentials will be different
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
Option 4: EasyEngine v3 to EasyEngine v4 Migration
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
Step 6: Restore the Database on the new server
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
Step 7: Set Up SSL Certificate
WordOps SSL Setup
If your site was secured with Let’s Encrypt and you’re using WordOps:
sudo wo site update blackmoreops.com -le
EasyEngine v4 SSL Setup
If you’re using EasyEngine v4:
sudo ee site ssl blackmoreops.com --le
Step 8: GCP-Specific Optimisations (Optional)
After migrating your WordPress site to GCP, consider these optimisations:
Set Up Cloud CDN (Recommended)
For a global audience, setting up Cloud CDN can significantly improve performance:
- Configure a load balancer in GCP
- Enable Cloud CDN on your backend service
- Update your DNS records to point to the load balancer IP
Configure Google Cloud Armor (Security)
Protect your WordPress site from common attacks:
- Go to Network Security > Cloud Armor in GCP Console
- Create a security policy with rules to block common WordPress attack patterns
- Apply the policy to your load balancer (if you’re using one)
Set Up Scheduled Backups
Ensure your WordPress site is backed up regularly:
- Create a scheduled snapshot of your boot disk:
gcloud compute disks snapshot DISK_NAME --snapshot-names=SNAPSHOT_NAME --zone=ZONE
- Set up automated backups using a cron job:
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/
Database Optimisation for GCP
Tune MySQL for better performance on GCP:
- Edit your MySQL configuration:
sudo vi /etc/mysql/my.cnf
- Add these settings for improved performance on GCP:
innodb_buffer_pool_size = 1G innodb_log_file_size = 256M innodb_flush_log_at_trx_commit = 2 innodb_flush_method = O_DIRECT
- Restart MySQL:
sudo systemctl restart mysql
Final Steps
- Test your migrated site by visiting blackmoreops.com
- Check that all functionality works as expected
- Update DNS records to point to your new server IP address (201.21.71.189)
- Monitor your site for any issues after the DNS changes propagate
Migration Between GCP Compute Engines
If you’re migrating between Google Cloud Platform (GCP) Compute Engine instances, you have additional options:
Same Region Migration
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/
Cross-Region Migration
When servers are in different GCP regions:
- You’ll need to use external IPs as internal IPs don’t communicate across regions by default
- Consider using maximum compression to reduce transfer sizes:
sudo rsync -avzh --progress --ignore-existing --compress-level=9 \ ubuntu@166.70.200.19:/var/www/blackmoreops.com/htdocs/ \ /var/www/blackmoreops.com/htdocs/
- For large sites, consider using Google Cloud Storage as an intermediate step to potentially reduce costs
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