To set up WordPress on a Google Cloud Compute Engine VM, you create a Linux VM instance, install a web server (Apache or Nginx), PHP, and MySQL, then download and configure WordPress. This guide walks through the entire process using the Google Cloud Console and command line, covering both quick and manual methods.
What You Need Before Starting
You need a Google Cloud account with billing enabled (new accounts get a free trial credit), and a project where you can create resources. Basic comfort with the command line is helpful, but you can follow along with copy-paste commands. The VM will run a Linux distribution—Ubuntu 22.04 LTS is a common choice because it’s well-supported and has long-term updates.
Creating Your Compute Engine VM
- Go to the Google Cloud Console and select or create a project.
- Navigate to Compute Engine > VM instances.
- Click Create Instance.
- Name your instance (e.g.,
wordpress-vm). - Choose a region and zone (pick one close to your audience).
- Select a machine type—the e2-micro (free tier eligible) works for testing, but for a real site, choose e2-small or e2-medium.
- Change the boot disk to Ubuntu 22.04 LTS and increase size to at least 20 GB.
- Allow HTTP and HTTPS traffic in the firewall section.
- Click Create.
After creation, note the external IP address—you’ll use it to connect and later to access your site.
Connecting and Installing the LAMP Stack
Click the SSH button next to your VM to open a browser-based terminal. Then run these commands to update the system and install Apache, MySQL, and PHP:
sudo apt update
sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php php-cli php-curl php-gd php-mbstring php-xml php-zip -y
This installs the core LAMP (Linux, Apache, MySQL, PHP) stack. Verify Apache is running by visiting your VM’s external IP in a browser—you should see the default Apache page.
Creating a Database for WordPress
WordPress stores all its content in a MySQL database. Access MySQL as root (using sudo) and create a database and user:
sudo mysql
CREATE DATABASE wordpress_db;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace your_strong_password with a secure password. Remember these details—you’ll need them during WordPress installation.
Downloading and Configuring WordPress
Download the latest WordPress package and extract it to the web root:
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo mv wordpress/* /var/www/html/
Set proper permissions so Apache can read and write files:
sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/
Now visit your VM’s IP address in a browser. The WordPress installer will appear. Select your language, then enter the database name, user, and password you created earlier. The installer will create the wp-config.php file automatically. If it asks for FTP credentials, that’s a permission issue—you can fix it by adding the following to wp-config.php:
define('FS_METHOD', 'direct');
Securing Your Installation
After installation, you should take a few security steps:
- Change the default WordPress admin username and use a strong password.
- Enable HTTPS by installing a free SSL certificate from Let’s Encrypt using Certbot (
sudo apt install certbot python3-certbot-apachethensudo certbot --apache). - Restrict access to your VM’s firewall—only allow ports 22 (SSH), 80 (HTTP), and 443 (HTTPS).
- Set up regular backups of your database and
/var/www/htmldirectory.
Common Problems and Fixes
Site not loading? Check that the VM’s firewall rules allow HTTP/HTTPS. In the Google Cloud Console, go to VPC network > Firewall and ensure there are rules for ports 80 and 443.
WordPress can’t connect to database? Double-check the database name, user, and password. Also ensure the MySQL user has privileges from localhost (not just any host).
White screen of death? This often happens due to a PHP error. Check the Apache error log with sudo tail -f /var/log/apache2/error.log and look for clues.
Slow performance? Consider enabling caching plugins and using a CDN. Also, ensure your VM has enough RAM—if you chose e2-micro, it may be too small for a production site.
Alternative: One-Click Deployment
If you prefer not to manually install everything, Google Cloud Marketplace offers pre-configured WordPress images. You can launch a VM with WordPress already installed by searching “WordPress” in the Marketplace. This saves time but gives you less control over the configuration. The manual method above is better for learning and customization.
Cost Considerations
Compute Engine pricing is per-second based on machine type and region. The e2-micro instance is eligible for the free tier (one per month in us-west1, us-central1, or us-east1). A typical e2-small running 24/7 costs around $15–$20 per month, plus storage costs (about $0.04/GB for standard persistent disk). You can reduce costs by stopping the VM when not in use, but that makes your site inaccessible.
Frequently Asked Questions
Can I use a Google Cloud SQL instead of MySQL on the VM?
Yes, Google Cloud SQL is a managed MySQL service that is more reliable and easier to back up. You would connect WordPress to it by changing the DB_HOST in wp-config.php to the Cloud SQL instance’s IP. This adds a small cost but offloads database maintenance.
How do I point my domain to the VM?
Go to your domain registrar and create an A record pointing to your VM’s external IP address. If you use Cloud DNS, you can create the record there and update your nameservers. Once the DNS propagates, you can access your site via the domain.
What if I need to migrate an existing WordPress site?
You can use a plugin like All-in-One WP Migration or Duplicator to export your site and import it on the new VM. Alternatively, manually copy the files and database using tools like rsync and mysqldump.
How do I update WordPress and plugins?
You can update from the WordPress admin dashboard. For security, always keep WordPress core, themes, and plugins updated. Before major updates, take a backup. If you lose access to the dashboard, you can update via WP-CLI (sudo wp-cli update).
Is this setup suitable for production?
Yes, but you should add a CDN, caching, and a monitoring service. Also, consider using a managed database and a load balancer if you expect high traffic. For small to medium sites, the manual setup with proper security is fine.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Infinity Essence in Sailor Piece: Farming and Uses
- Apollo.io Alternatives for Sales Prospecting
- Deploy AI Agents in a Service Desk With Human Oversight
- AIM and Yahoo Profiles: When Did You Last Look?
- Best Smartwatch Under ₹5,000 in India: What to Buy
- Chat History vs Saved Memory in AI Assistants