Step-by-Step Reference: Migrating WordPress to Google Cloud Platform
Avoid mistaking migration for a pure file-transfer exercise. Migrating WordPress to Google Cloud is fundamentally about architecting for performance, resilience, and scale. This walkthrough assumes root or sudo access and basic command-line literacy. If you need full managed hosting, Google Cloud’s Marketplace images or Cloud Run might offer a faster route, but for control and flexibility, VMs remain standard.
Problem Statement: Outgrowing Shared Hosting
Classic cPanel shared hosting often fails under concurrency spikes or resource contention. Moving to Google Cloud Compute Engine eliminates noisy-neighbor problems and allows explicit scaling. Expect changes—particularly in operational responsibilities, monitoring, and backups.
Prerequisites
- Active Google Cloud account (billing enabled)
- Existing WordPress deployment (LAMP stack, ideally with PHP ≥7.4)
- Access credentials for both old and new servers
- Familiarity with SSH, MySQL, Linux command-line tools
1. Project and VM Provisioning
Google Compute Engine VMs offer direct server access, suitable for granular tuning.
Steps:
- In Google Cloud Console, navigate:
IAM & Admin → Create Project
- Name the project (e.g.,
wp-gcp-migration
)
Provision a Compute Engine instance:
- Navigate:
Compute Engine → VM instances → Create Instance
- Suggested region: geographically close to primary user base (latency matters)
- Machine type: for low-medium traffic,
e2-medium
(2 vCPUs, 4 GB RAM) suffices; for higher loads, considern2-standard-4
- Boot disk:
Ubuntu 22.04 LTS
(checked May 2024), 20 GB SSD minimum - Enable both HTTP and HTTPS traffic (Firewall settings)
Typical provisioning time: < 2 minutes.
Gotcha: GCP assigns ephemeral external IPs by default. Reserve a static IP if DNS stability is required.
2. Environment Preparation
Initial SSH connection:
From Cloud Console, select the VM → SSH.
System update and package install:
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install apache2 mysql-server php8.1 php8.1-mysql libapache2-mod-php8.1 unzip -y
Replace PHP version above if necessary for plugin compatibility.
Secure MySQL:
sudo mysql_secure_installation
Set root password; accept defaults. Disallow root remote login. This step is non-negotiable.
3. Data Export from Legacy Server
You need both the WordPress files and the database.
Files:
- Compress entire WordPress directory. If possible, exclude cache/data-heavy directories to reduce file size.
tar czf wordpress_files.tar.gz /var/www/html/
Database:
From legacy host:
mysqldump -u wp_user -p wp_db > wp_db_backup.sql
Expect dump files to exceed 100 MB for large media libraries. Watch for character set errors or timeouts.
4. Transferring to Google Cloud VM
File transfer via SCP:
From local machine:
scp wordpress_files.tar.gz [USERNAME]@[VM_EXTERNAL_IP]:~
scp wp_db_backup.sql [USERNAME]@[VM_EXTERNAL_IP]:~
Alternatively, for large uploads, use gsutil
and stage on a Storage bucket.
5. Installing WordPress on GCP
Unpack files:
sudo tar xzf wordpress_files.tar.gz -C /var/www/html/ --strip-components=1
--strip-components=1
removes redundant path levels.
Update file permissions:
sudo chown -R www-data:www-data /var/www/html/
sudo find /var/www/html/ -type f -exec chmod 644 {} \;
sudo find /var/www/html/ -type d -exec chmod 755 {} \;
6. Database Setup
Create new database/user on GCP:
sudo mysql -u root -p
CREATE DATABASE wp_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'a_strong_password_2024';
GRANT ALL PRIVILEGES ON wp_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Import backup:
mysql -u wp_user -p wp_db < wp_db_backup.sql
Potential error to troubleshoot:
ERROR 1064 (42000) at line 301: You have an error in your SQL syntax;
- Usually points to mismatched MySQL versions or plugins dumping engine-specific syntax. Check/strip
DEFINER=
lines if migrating between major versions.
7. Configure wp-config.php
Change database credentials to match the new environment:
sudo nano /var/www/html/wp-config.php
Adjust
define('DB_NAME', 'wp_db');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', 'a_strong_password_2024');
define('DB_HOST', 'localhost');
Note: For Cloud SQL, use the socket path for DB_HOST
. Here, for local MySQL, use localhost
.
8. Web, Rewrite, and SSL Configuration
Enable mod_rewrite for pretty permalinks:
sudo a2enmod rewrite
sudo systemctl restart apache2
Allow .htaccess overrides:
Edit Apache site config:
sudo nano /etc/apache2/sites-available/000-default.conf
Insert inside <VirtualHost *:80>
:
<Directory /var/www/html/>
AllowOverride All
</Directory>
Restart Apache.
SSL via Certbot:
sudo apt-get install certbot python3-certbot-apache -y
sudo certbot --apache -d example.com -d www.example.com
Choose to redirect HTTP to HTTPS.
Known issue: Let's Encrypt rate limits new domains. If hitting rateLimited
, schedule retry after one hour.
9. DNS Cut-over
Change the domain’s A record to your VM external (preferably static) IP. Example (replace placeholder):
Type | Name | Value | TTL |
---|---|---|---|
A | @ | 34.102.123.45 | 3600 |
DNS propagation may take anywhere from minutes to 24 hours. Use dig
or Google Dig Tool to confirm propagation.
10. Sanity Checks
- Browse to site root and wp-admin.
- Confirm permalinks / rewrites work; if broken, re-save Permalink Settings.
- Verify SSL is green in browser.
- Run
apache2ctl -S
for vhost issues. - Check error logs:
/var/log/apache2/error.log
anddebug.log
in WordPress if enabled.
Optimization & Post-migration Notes
- Backups: Set up Compute Engine snapshot schedules and/or leverage plugins like UpdraftPlus to Google Cloud Storage.
- VM Sizing: Right-size instances based on real-world
top
,htop
, and GCP Monitoring usage. Don’t overspend. - CDN: Google Cloud CDN integrates with Load Balancer; not directly with naked VMs unless paired with a backend service. For most, Cloudflare is simpler.
- Image/Caching Plugins: Use ShortPixel or Imagify for compressing existing uploads. W3 Total Cache suffices; consider memcached or Redis if scaling later.
- Monitoring: Deploy Stackdriver Monitoring and set thresholds for CPU and disk usage—don’t wait for alerts at 95% fill.
Alternative: For less manual management, Cloud SQL (managed MySQL) is worth evaluating, though comes with added complexity and cost considerations.
Reference Example: Snapshots via gcloud
gcloud compute disks snapshot [DISK_NAME] --snapshot-names=[SNAPSHOT_NAME] --zone=[ZONE]
Schedule this via cron for weekly retention.
Final Note
Moving WordPress to GCP is rarely completely seamless—testing, error log inspection, and occasional plugin conflicts should be expected. The result gives full infrastructure control and the ability to fit hosting to business needs, rather than vendor constraints. Trade-offs involve more hands-on updates and security vigilance.
Questions about reverse proxying, Cloud SQL, or scaling? Initiate a direct inquiry with details—use cases differ.