gcloud projects create [project-name] --name="[Project Nice Name]" --set-as-default
# Otherwise set an existing project as default
gcloud config set project [project-name]
WARNING: the region can't be changed after. You can use GCPing to find the one with the lowest latency from your country.
gcloud app create --region=[europe-west3]
This will create a new DB instance named wp-website
with a root
user password set to [password] (replace it with a 32-char random password).
IMPORTANT: Choose the same region of the GAE app or the inter-region network latency will impact you site performance massively.
gcloud sql instances create [wp-website] --root-password=[password] --region=[europe-west3] --tier=[db-f1-micro]
It might take up to 10 mins to create the instance.
Connect to the instance
gcloud sql connect [wp-website] --user=root
You will be asked for the root
user password set up in the step 2.1).
Create the database and an user that can only R/W to this DB.
In this case we will create a database named wordpress
and a user wordpress_user
with the password [mysql-user-password]
(replace it with a 32-char random password).
CREATE DATABASE wordpress; GRANT ALL ON wordpress.* TO 'wordpress_user'@'%' IDENTIFIED BY '[mysql-user-password]';
and exit
.
Open the /env_variables.yaml
file and configure:
Insert the instance, DB and user credentials set up in the steps 2.1) and 2.2) in the corresponding vars:
DB_NAME: 'wordpress'
DB_USER: 'wordpress_user'
DB_PASSWORD: '[mysql-user-password]'
DB_HOST: ':/cloudsql/project-name:europe-west3:wp-website' # You can get the DB connection string via the command `gcloud sql instances describe [wp-website] --format="value(connectionName.scope())"`
Replace the default wp_
prefix with something custom, to prevent SQL injection attacks. Usually adding 2-3 random chars before the _
it's enough.
DB_PREFIX: 'wpxx_'
For this bedrock installation the siteurl
always has a /wp
suffix.
WP_HOME: 'https://[project-name].appspot.com'
WP_SITEURL: 'https://[project-name].appspot.com/wp'
- Visit https://roots.io/salts.html
- Copy the
Env format
block: the var names must be uppercase. - Replace the empty vars with this whole block
- Replace each var's
='
assign with the: '
assign
AUTH_KEY: '[...]'
SECURE_AUTH_KEY: '[...]'
LOGGED_IN_KEY: '[...]'
# ...
Replace other WP vars accordingly..
Test the app in the local environment before deploying to production.
gcloud beta app deploy app.yaml cron.yaml --no-cache
The beta's --no-cache
flag is actually REQUIRED due to this bug in GAE composer installation procedure
Wait for the app to be successfully deployed.
- Visit the app URL setup above and wordpress should redirect you to the installation page. Follow the wizard and don't forgot the admin password.
- Activate all the needed plugins
- Activate the theme and initialize it by visiting the Customizer page (if required).
- Connect Jetpack (if required)
- Add users/admins
- Check that you have enabled the
Google cloud Storage
plugin - Log in the Wordpress Admin and from the Main menu select
Settings > Media
- In the
Bucket name for media upload
field insert your GCS bucket url. If you don't need to use a custom bucket, GAE creates a default bucket namedgs://[project-name].appspot.com
Allow anonymous users to read uploads from the default bucket
gsutil defacl ch -u AllUsers:R gs://[project-name].appspot.com
Now it's time to set-up your theme and import o write your contents.
Replace the *.appspot.com
URL with a custom domain.
WP_HOME: 'https://example.com'
WP_SITEURL: 'https://example.com/wp'
gcloud app deploy app.yaml
- Visit the App Engine Custom Domain page
- Click on [
Add Custom Domain
] button - Follow the GAE domain configuration wizard
- Insert/replace the provided records in the domain DNS zone
- Wait 5-10 mins for the SSL Certificates