How to Install WordPress on Google Cloud Run with SSL


Steps to Deploy WordPress on Google Cloud Run

  1. Create Service accounts for Google Cloud SQL, Google Cloud Storage.
  2. Prepare Dockerfile, Custom PHP configuration, WordPress Media Offload plugin, .htaccess, and the service account Json key.
  3. Build docker image and push to Google Container registry.
  4. Create Cloud Run service using the image.
  5. Map custom domain and install SSL.
  6. Point Domain to Cloud Run
  7. Install WordPress
  8. Setup WordPress Offload plugin to store media files on Google Cloud Storage.

Enable APIs for Cloud SQL

  • CloudSQL API
  • CloudSQL Admin API

Create Service accounts

Cloud SQL >> Cloud SQL Admin
Cloud Storage >> Storage Admin

Create Google Cloud Storage Bucket

Cloud SQL Details

Prepare Docker Setup

mkdir cloudrun
cd cloudrun

Setup .htaccess

nano .htaccess
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Configure Custom PHP settings

nano custom-php.ini
memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
max_input_time = 1000
max_input_vars = 5000

Add Service Account key

Custom WP-Config

nano wp-config.php
define('FORCE_SSL_ADMIN', true);
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
define( 'DB_NAME', getenv('DB_NAME') );
define( 'DB_USER', getenv('DB_USER') );
define( 'DB_PASSWORD', getenv('DB_PASSWORD') );
define( 'DB_HOST', getenv('DB_HOST') );
define( 'DB_CHARSET', 'utf8' );define( 'DB_COLLATE', '' );define('AS3CF_SETTINGS', serialize(array(
'provider' => 'gcp',
'key-file-path' => '/var/www/html/service_account_conf.json',
define('AUTH_KEY', 'YOUR_VALUE');
define('NONCE_KEY', 'YOUR_VALUE');
define('AUTH_SALT', 'YOUR_VALUE');
$table_prefix = 'CblEt_';define( 'WP_DEBUG', false );if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
require_once ABSPATH . 'wp-settings.php';

Upload Offload Media Plugin

cd wp-content/plugins
rm -rf
cd ~/cloudrun
  1. .htaccess
  2. custom-php.ini
  3. service_account.json
  4. wp-config.php
  5. wp-content/plugins which has your offload media plugin.

Create Dockerfile

nano Dockerfile
FROM wordpress:php8.0-apacheCOPY ./custom-php.ini /usr/local/etc/php/conf.d/WORKDIR /var/www/html
COPY ./wp-config.php /var/www/html/wp-config.php
COPY ./.htaccess /var/www/html/.htaccess
COPY ./offload.json /var/www/html/offload.json
COPY ./wp-content /var/www/html/wp-content/

Build Image and Push to Registry

gcloud builds submit --tag>image_name

Create Cloud Run Service

Select Container Image

Configure Container Details

Configure Variables & Secrets

  • DB_NAME database name
  • DB_USER username
  • DB_PASSWORD user password
  • DB_HOST :/cloudsql/instance_connection_name

Configure Connections

Configure Public access

Configure Custom Domain

Configure Offload Media Plugin




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Installation and Set Up of Web Applications on Google Cloud