WordPress

Running WordPress on App Engine Standard Environment

I have just added a support for App Engine Standard Environment to the WordPress helper script. In this post, we will walk through how to run WordPress on App Engine Standard Environment. Oh but which environment to choose; flexible, or standard? You may want to read The App Engine Environments before the decision.

Prerequisites

Configure Google Cloud SDK

Configure Google Cloud SDK with your account and the project.

$ gcloud auth login
...
...
$ gcloud config set project YOUR_PROJECT_ID

Let’s configure the GCS bucket for later use. The default App Engine bucket looks like YOUR_PROJECT_ID.appspot.com. Change the default acl of that bucket as follows:

 $ gsutil defacl ch -u AllUsers:R gs://YOUR_PROJECT_ID.appspot.com

Create and configure a Cloud SQL first generation instance

We will use wp for various resource names; in particular for the instance name and the database name.

Go to Cloud SQL console and create a new fist generation instance wp and create a new database wp. Go to Access Control -> Users, then change the password for root@localhost user. You will later use this password for accessing from App Engine.

Create a database and a user on local mysql

Create a database and a user on the local mysql server. This dummy database is needed for maintenance reasons, in particular, to update your plugins and themes easily. You can use this local database for running your WordPress locally, or for running a tool named wp-cli for maintenance purpose.

Assuming you have already installed and configured the mysql server, use mysql command to create a database and a user as follows (don’t use the example password below):

$ mysql -h 127.0.0.1 -u root -p
mysql> create database wp;
mysql> create user 'wp'@'localhost' identified by 'PASSWORD';
mysql> grant all on wp.* to 'wp'@'localhost';
mysql> exit
Bye

Download and configure WordPress

We provide a convenient tool for downloading and configuring WordPress. Let’s use this tool here. First, clone one of our git repos:

$ git clone https://github.com/GoogleCloudPlatform/php-docs-samples.git

Then cd into the `php-docs-samples/appengine/wordpress` directory and run `composer install`.

$ cd php-docs-samples/appengine/wordpress
$ composer install

Then run the `wordpress-helper.php` as follows:

$ php wordpress-helper.php setup -d ~/my-wordpress-project

After answering few questions, you’ll have fully working WordPress installation at `~/my-wordpress-project` directory.

Run WordPress locally

Chdir to the project directory and run the following command to run WordPress locally:

$ cd ~/my-wordpress-project
$ vendor/bin/wp server --path=wordpress

If you’re on Windows, use wp.bat:

> cd C:\my-wordpress-project
> vendor/bin/wp.bat server --path=wordpress

Then access http://localhost:8080/. Finish the installation step. Login to the Dashboard and update if any of the plugins have update.

Now it’s ready for the first deployment.

Deployment

Deploy your WordPress as follows:

$ gcloud app deploy --promote --stop-previous-version app.yaml cron.yaml

Then access your site at https://PROJECT_ID.appspot.com/ and finish the WordPress installation process (Note: please do this immediately after the first deployment).

Go to the Dashboard, and in the Plugins page, activate the App Engine WordPress plugin and Batcache Manager plugin. Try uploading a media and confirm the image is uploaded to the GCS bucket.

Check if Batcache is working

In the plugin page, you should see these 2 drop-ins are activated as follows:

WP-dropins

To make sure it’s really working, you can open an incognito window and visit the site because the cache plugin only serves from cache to anonymous users. Then go to the memcache dashboard in the Cloud Console and check the hit ratio and number of items in cache.

Various workflows

Install/Update plugins/themes

Because the wp-content directory on the server is read-only, you have to do this locally. Run WordPress locally (`vendor/bin/wp server –path=wordpress`) and update plugins/themes in the local Dashboard, then deploy, then activate them in the production Dashboard. You can also use the wp-cli utility in the project’s vendor directory as follows (you have to run Cloud SQL Proxy or local mysql server for this tool to work):

# To update all the plugins
$ vendor/bin/wp plugin update --all --path=wordpress
# To update all the themes
$ vendor/bin/wp theme update --all --path=wordpress

Remove plugins/themes

First Deactivate them in the production Dashboard, then remove them completely locally. The next deployment will remove those files from the production environment.

Update WordPress itself

Most of the case, just download the newest WordPress and overwrite the existing wordpress directory. It is still possible that the existing config files are not compatible with the newest WordPress, so please update the config file manually in that case.

Conclusion

We walked though how to run WordPress on App Engine standard environment. It performs well because we’re leveraging Memcached service provided by App Engine. Also thanks to the App Engine autoscaler, Google will automatically spin up new instances when your site is getting lots of traffic.

If you need to run new WordPress site, please give this guide a try and let us know what you think.

40 comments on “Running WordPress on App Engine Standard Environment

  1. Hi,

    I got the following error while running “composer install”, Any suggestion for this ?

    Problem 1
    – Installation request for symfony/console v3.0.4 -> satisfiable by symfony/console[v3.0.4].
    – symfony/console v3.0.4 requires php >=5.5.9 -> your PHP version (5.4.38) does not satisfy that requirement.
    Problem 2
    – Installation request for guzzlehttp/guzzle 6.2.0 -> satisfiable by guzzlehttp/guzzle[6.2.0].
    – guzzlehttp/guzzle 6.2.0 requires php >=5.5.0 -> your PHP version (5.4.38) does not satisfy that requirement.
    Problem 3
    – Installation request for guzzlehttp/promises 1.1.0 -> satisfiable by guzzlehttp/promises[1.1.0].
    – guzzlehttp/promises 1.1.0 requires php >=5.5.0 -> your PHP version (5.4.38) does not satisfy that requirement.
    Problem 4
    – Installation request for symfony/dom-crawler v3.0.4 -> satisfiable by symfony/dom-crawler[v3.0.4].
    – symfony/dom-crawler v3.0.4 requires php >=5.5.9 -> your PHP version (5.4.38) does not satisfy that requirement.
    Problem 5
    – Installation request for symfony/yaml v3.0.4 -> satisfiable by symfony/yaml[v3.0.4].
    – symfony/yaml v3.0.4 requires php >=5.5.9 -> your PHP version (5.4.38) does not satisfy that requirement.
    Problem 6
    – symfony/yaml v3.0.4 requires php >=5.5.9 -> your PHP version (5.4.38) does not satisfy that requirement.
    – phpunit/phpunit 4.8.24 requires symfony/yaml ~2.1|~3.0 -> satisfiable by symfony/yaml[v3.0.4].
    – Installation request for phpunit/phpunit 4.8.24 -> satisfiable by phpunit/phpunit[4.8.24].

  2. Also I tried to upload the theme plugin in my local. This use to work but not with this instance its showing the error.

    Also I tried to upload plugin locally (Genesis and theme). Which worked before now its showing the following error. (edited)

    [2:06]
    Unpacking the package…

    Installing the plugin…

    The package could not be installed. No valid plugins were found.

    Plugin install failed.

  3. Hi Rama,

    When do you get the DB connection error? If it’s when you try to run WordPress locally, what exact command line did you use? Also can you provide a link for the plugins and themes? Are you trying to install them on the UI? If those plugins are just zip files, what about just extracting to `wordpress/wp-content/plugins` or `wordpress/wp-content/themes`?

    1. The DB error is with the GAE. The wordpress runs locally but not able to upload the plugin through the wp-admin as it complains “The package could not be installed. No valid plugins were found”.

      Command to run locally, is the same you specified in the blog. “vendor/bin/wp server –path=wordpress”

      I tried extracting to `wordpress/wp-content/themes` folder but it doesn’t show up in wp-admin –> Plugins console to activate.

  4. Is there a way to track the deploy status using gcloud ?. My app use to get deployed in 2/3 mins, this was gradually slowing down and now its talking 30/40 mins. It would be nicer if the deployed status is showed in percentage, and more idle is the upload data speed.

  5. rama@ It’s not normal if your deployment takes 30/40 minutes. You can enable debugging output by running `gcloud config set verbosity DEBUG` to see what is taking such long time. You can disable the debugging output by `gcloud config set verbosity DEFAULT`.

    1. Thanks. It seems better now, Still it takes 15/20 mins. Why is it uploading all the files during deployment ?, including my upload folder. Can something be done about that, my upload folder is 70% of the deployment size.

      1. What are there in the upload folder? Are they needed?

        With App Engine, we use Google Cloud Storage for media upload, so I don’t think you need to upload `upload` folder.

  6. I installed until I got to localhost:8000, however when I go the browser, the page keeps reloading and no errors are being shown on the page. How do I show the database setup page?

  7. I completed the process, but when I do localhost on the browser the pages do not open and there is no error. What could I be missing?

    1. @James

      Thanks for the report. What do you mean by page keeps reloading? Which OS are you using?

      Maybe you can deploy the app and proceed. It is not strictly required to run WordPress locally anyways.

          1. @tmatsuo, can I send you my wp-config page so you can look at it? Maybe that is where the error is because at the moment, everything has failed so far

            Also for comments, could you enable notifications so that when you respond I get a notification on email

  8. @James

    “everything has failed” doesn’t give me any clue for helping you. Yeah maybe you can send me your config file to tmatsuo@google.com, with other information like what exactly you did and what is happening. I’ll take a look.

    1. @tmatsuo, did you find out what was wrong with the setup?

      We can do a remote session so I can see the steps, because I think its something minor that’s causing the issue.

    2. I have the same problem as James. When attempting to run locally, the local wp server process locks up and has to be killed. I’d wager it is something about the MySQL environment. If the database parameters are not configured properly, wp server serves up error info as expected. But as soon as database parameters are set to the correct values, attempting to load up a page freezes the entire server process. This is a showstopper as far as the using GAE for WP tutorial is concerned because having a local development environment is critical in my development workflow.

  9. Are there major improvements to the 2nd gen cloud sql? I am running WordPress on Standard Environment with Cloud SQL 1st gen. I have cache setup and it’s flying. I’m only running across latency/speed issues when I have a large amount of memcache RPCS or a database hit and I’m curious if they are related to performance in 1st gen cloud sql and if upgrading to Cloud SQL 2nd gen would fix these issues.

    The main issue is related to latency when hitting the database. If I delete 20 users or 10 categories I’m getting around 20 second load times which seems crazy. In Trace it looks like the RPCs are all performing very quickly however there is a large amount of untraced time. Uploading images also is a 5-7second round trip which seems too long. It appears the more RPCs I have the larger the untraced time is. For example, if I have a full page cache it’s only 3 RPCs to memcache.get and untraced time is around 300ms which is okay but if I have 60 or 70 RPCs using memcache.get I can have around ~700ms of untraced time. The 70 RPCs will complete in around 70ms though.

    I’m wondering if I’m missing something and if you could point me in the right direction or perhaps where to poke around. I’m running out of ideas.

    and thanks for all your updates/tutorials to the wordpress/gae projects

      1. I was able to get the domain up and running, now the only challenge is after deploying the site, still getting the error that says, database connection cannot be found.

        However the site is working properly locally. The memcache plugin says has already been defined. Causing an error.

        Also under your deployment page, change gcloud preview remove the preview since its no longer needed.

  10. I was able to get the domain up and running, now the only challenge is after deploying the site, still getting the error that says, database connection cannot be found.

    However the site is working properly locally. The memcache plugin says has already been defined. Causing an error.

    Also under your deployment page, change gcloud preview remove the preview since its no longer needed.

      1. @tmatsuo

        The SQL instance has already been created
        The database has been created
        The username has been created
        The password has been created

        All this matches the wp-config page, but does not work online.

        1. @tmatsuo

          The SQL instance has already been created
          The database has been created
          The username has been created
          The password has been created

          All this matches the wp-config page, but does not work online.

          Also, the Memcached Plugin is creating a fatal error because wp_cache_add has already been declared

          1. James@

            It’s hard to troubleshoot with the comments. Do you want to have video meeting for debugging your issue? If so, contact me at tmatsuo at google.com.

  11. Hi tmatsuo.

    gcloud app deploy –promote –stop-previous-version app.yaml cron.yaml

    The above command to deploy is not working anymore. How to go about ?

    Thanks,
    Rama.

  12. Hi, is it possible to turn on WP_DEBUG in the App Engine standard environment and have access to the wordpress logs? I can’t seem to find a way to access those logs after setting WP_DEBUG to true.

Leave a Reply

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

By submitting this form, you accept the Mollom privacy policy.