Installing WordPress on Google Cloud Platform with Compute Engine

Contents

Installing WordPress on Google Cloud Platform with Compute Engine

A comprehensive, step-by-step guide to deploy a production-ready WordPress site on GCP.

Overview

This tutorial walks you through every stage of launching WordPress on Google Cloud Compute Engine. You will configure networking, provision resources, install a LAMP stack, optimize security, and prepare for production traffic.

1. Prerequisites

  • Active Google Cloud Platform account with billing enabled.
  • Basic familiarity with Linux commands and SSH.
  • Registered domain name (optional, for production).
  • gcloud CLI installed locally or via Cloud Shell.

2. Project Setup API Enablement

  1. Open the GCP Console and create or select a project.
  2. Enable required APIs:
    • Compute Engine API
    • Cloud SQL Admin API (if using Cloud SQL)
  3. Set your default project and zone:
    gcloud config set project YOUR_PROJECT_ID
    gcloud config set compute/zone us-central1-a

3. Provisioning a Compute Engine VM

We recommend choosing an E2 or N1 machine type for small to medium sites.

Machine Type vCPU Memory
e2-micro 2 1 GB
n1-standard-1 1 3.75 GB
  1. Create the VM via CLI:
    gcloud compute instances create wordpress-vm --machine-type=e2-micro --image-family=debian-11 --image-project=debian-cloud --boot-disk-size=20GB --tags=http-server,https-server
  2. Allow HTTP(S) traffic:
    gcloud compute firewall-rules create default-allow-http --allow tcp:80
    gcloud compute firewall-rules create default-allow-https --allow tcp:443

4. SSH LAMP Stack Installation

Connect to your VM:

gcloud compute ssh wordpress-vm

Update packages and install Apache, MySQL, PHP:

sudo apt-get update
sudo apt-get install -y apache2 mysql-server php php-mysql php-gd php-xml php-mbstring unzip
  

4.1. Secure MySQL

sudo mysql_secure_installation
  

Create database and user:

sudo mysql -u root -p
CREATE DATABASE wordpress
CREATE USER wpuser@localhost IDENTIFIED BY StrongPassword
GRANT ALL PRIVILEGES ON wordpress. TO wpuser@localhost
FLUSH PRIVILEGES
EXIT
  

5. Download and Configure WordPress

  1. Download and extract WordPress:
    wget https://wordpress.org/latest.tar.gz
    tar -xvf latest.tar.gz
    sudo mv wordpress /var/www/html/
          
  2. Adjust ownership and permissions:
    sudo chown -R www-data:www-data /var/www/html/wordpress
    sudo find /var/www/html/wordpress -type d -exec chmod 755 {} 
    sudo find /var/www/html/wordpress -type f -exec chmod 644 {} 
          
  3. Configure database settings:
    cd /var/www/html/wordpress
    cp wp-config-sample.php wp-config.php
    sudo sed -i s/database_name_here/wordpress/ wp-config.php
    sudo sed -i s/username_here/wpuser/ wp-config.php
    sudo sed -i s/password_here/StrongPassword/ wp-config.php
          

6. Apache Virtual Host Configuration

Create a site configuration:

sudo tee /etc/apache2/sites-available/wordpress.conf ltltEOF
ltVirtualHost :80gt
    ServerName your-domain.com
    DocumentRoot /var/www/html/wordpress
    ltDirectory /var/www/html/wordpressgt
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    lt/Directorygt
    ErrorLog {APACHE_LOG_DIR}/wordpress-error.log
    CustomLog {APACHE_LOG_DIR}/wordpress-access.log combined
lt/VirtualHostgt
EOF
  

Enable modules and site:

sudo a2enmod rewrite
sudo a2ensite wordpress.conf
sudo systemctl restart apache2
  

7. Finalizing Installation Security

  • Visit http://YOUR_EXTERNAL_IP or domain to complete the WordPress setup wizard.
  • Install an SSL certificate via Let’s Encrypt:
    sudo apt-get install -y certbot python3-certbot-apache
    sudo certbot --apache -d your-domain.com
          
  • Harden configuration by disabling file editing in wp-config.php:
    define(DISALLOW_FILE_EDIT, true)
          

8. Scaling, Backups Monitoring

  • Consider Cloud SQL for managed database: see Cloud SQL MySQL docs.
  • Automate backups with gcloud compute snapshots or managed services.
  • Use Cloud Monitoring and Cloud Logging (Stackdriver Monitoring).
  • Implement a Load Balancer and Autoscaler for high availability.

Conclusion

By following these steps, you will have a robust, secure, and scalable WordPress installation on Google Cloud Compute Engine. Expand your setup with managed database options, CDN integration, and advanced monitoring to support growth and performance. Happy publishing!



Acepto donaciones de BAT's mediante el navegador Brave 🙂



Leave a Reply

Your email address will not be published. Required fields are marked *