In this codelab, you'll learn how to run WordPress on App Engine Flexible Environment.
If you don't already have a Google Account (Gmail or Google Apps), you must create one. Sign-in to Google Cloud Platform console (console.cloud.google.com) and enable billing in the Developers Console in order to use Google Cloud resources like Cloud SQL and Cloud Storage. Then create a new project:
Remember the project ID, a unique name across all Google Cloud projects (the name above has already been taken and will not work for you, sorry!). It will be referred to later in this codelab as PROJECT_ID
.
Running through this codelab shouldn't cost you more than a few dollars, but it could be more if you decide to use more resources or if you leave them running (see "cleanup" section at the end of this document). Prices are documented here: App Engine Flexible Environment, Cloud SQL & Cloud Storage
New users of Google Cloud Platform are eligible for a $300 free trial.
While you can use your laptop, in this codelab we will be using Google Cloud Shell, a command line environment running in the Cloud.
This Debian-based virtual machine is loaded with all the development tools you'll need. It offers a persistent 5GB home directory, and runs on the Google Cloud, greatly enhancing network performance and authentication. This means that all you will need for this codelab is a browser (yes, it works on a Chromebook).
To activate Google Cloud Shell, from the developer console simply click the button on the top right-hand side (it should only take a few moments to provision and connect to the environment):
Once connected to the cloud shell, you should see that you are already authenticated and that the project is already set to your PROJECT_ID
:
gcloud auth list
Credentialed accounts: - <myaccount>@<mydomain>.com (active)
gcloud config list project
[core] project = <PROJECT_ID>
If for some reason the project is not set, simply issue the following command :
gcloud config set project <PROJECT_ID>
Looking for your PROJECT_ID
? Check out what ID you used in the setup steps or look it up in the console dashboard:
IMPORTANT: Finally, set the default zone and project configuration:
gcloud config set compute/zone us-central1-f
You can choose a variety of different zones. Learn more in the Regions & Zones documentation.
In this step, you will make sure the Cloud SQL API is enabled and create Cloud SQL instance, a Cloud Storage bucket and configure them for your WordPress blog.
If you're running this lab on qwiklab skip this step. Visit this link to make sure the Cloud SQL API is enabled.
In this step, you created a Google Developer Console project and created a Cloud SQL instance and Cloud Storage bucket and configured them for your WordPress blog.
First install Composer with the following commands:
mkdir -p ${HOME}/bin
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === rtrim(file_get_contents('https://composer.github.io/installer.sig'))) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --filename=composer --install-dir=${HOME}/bin
export PATH=${HOME}/bin:${PATH}
Now you should run composer as follows:
composer ______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 1.2.0 2016-07-19 01:28:52 ... ...
If this step doesn't work, visit the Composer Download page in a new browser and follow the instructions there.
In this step, you installed Composer, a dependency management tool for PHP in your Google Cloud Shell environment.
In Cloud Shell on the command-line, run the following command to clone the Github repository:
git clone https://github.com/GoogleCloudPlatform/php-docs-samples.git
Change directory into php-docs-samples/appengine/wordpress
.
cd php-docs-samples/appengine/wordpress
Install dependencies with the following command:
composer install --no-dev
Run the helper script to see the usage:
php wordpress-helper.php help setup
The helper script will help you create your WordPress project. Run the command below:
php wordpress-helper.php setup -d ${HOME}/my-wordpress-project
and follow the instructions as shown below:
$ php wordpress-helper.php setup -d ${HOME}/my-wordpress-project We will use the directory: /home/xxxx/my-wordpress-project. If the directory exists, we will override the contents. Do you want to continue? (Y/n) <Hit Enter> A directory /home/xxxx/my-wordpress-project was created. Please select the App Engine Environment (defaults to Flexible Environment) [0] Flexible Environment [1] Standard Environment > <Hit Enter> Creating a new project for: Flexible Environment Please select the region of your Cloud SQL instance (defaults to us-central1) [0] us-central1 [1] us-east1 [2] europe-west1 [3] asia-east1 > <Hit Enter (choose the number if you choose the other region)> Using a db_region: us-central1 Downloading the WordPress archive... Downloaded the WordPress archive. Downloading the Batcache plugin... Downloaded Batcache plugin. Downloading the Memcached plugin... Downloaded Memcached plugin. Copying drop-ins... Please enter project_id (mandatory input): <Type your project id and hit enter - you can find your GCP project ID on your Qwiklabs page> Please enter db_instance (defaults to 'wp'): <Hit Enter> Please enter db_name (defaults to 'wp'): <Hit Enter> Please enter db_user (defaults to 'wp'): <Hit Enter> Please enter db_password (mandatory input): <Type your password for the database user> Do you want to use the same db user and password for local run? (Y/n) <Hit Enter> ... ... Your WordPress project is ready at /home/xxxx/my-wordpress-project
Then cd into the project directory:
cd ${HOME}/my-wordpress-project
In this step, you created your WordPress project in your Google Cloud Shell VM.
Deploy the project by running the following command:
gcloud app deploy
If you prompted to choose a region, chose us-central. This command will take several minutes. After it succeeds, visit your blog by opening https://YOUR-PROJECT-ID.appspot.com/, then you'll see the WordPress installation screen like this:
Fill the following field
Then click Install WordPress. Your WordPress blog will be ready in seconds!
This plugin allows you to upload media files to the Cloud Storage bucket and serve from there, instead of using the local file system. Because App Engine can spawn a new server for you, the media files must be shared between all the servers.
Feel free to play around with the WordPress Admin UI, especially the Media uploader which is configured to upload the images to your Cloud Storage bucket. You can browse your Cloud Storage bucket on the Cloud Storage Browser.
Now you have a WordPress blog running on App Engine Flexible Environment.
You learned how to run WordPress blog on App Engine Flexible Environment.