A handy tip for local development of PHP on App Engine

Daniel Holmes
Jan 4, 2018 · 2 min read

In this article, I overview the backstory behind the tip and then tell you what it is and how you can use it.

The Backstory

My team uses Google App Engine extensively with our PHP applications and until recently we were using a customised version (read old version) of Google’s php-docker docker image which we used both in production as well as our local testing environments.

One of our recent requirements meant that I had to touch the php-docker image and upon the touching of the image, like a lot of old-code projects things started to break horribly. The datedness of the image caused a cascade of failures that needed to be sorted.

As a result I researched and in consultation with my team chose to move back to Google’s current php-docker image as we felt it had enough stability and features to replace our custom image. After doing a couple test runs I figured out that:

Volumes didn’t work well with the php-docker default image

The reason being, that the entrypoint.sh script that is run right before the docker image runs the web server, likes to chmod everything to some hardcore permissions. This likely means that locally you’ll have no permissions to your own files if you’re using a volume and in the case of our app, our cache folder becomes unwritable.

To solve this I worked with the GCP team to introduce a new feature into the php-docker image that allows you to skip this lockdown process if you’re doing local development.

Skipping Lockdown Locally

It’s a very simple matter to skip lockdowns locally now. Consider the following docker command which would spin up a new php-docker instance using your local directory as a volume and /app/public where your index.php file is:
docker run -v /home/daniel/Repositories/my-project:/app -e DOCUMENT_ROOT=/app/public --name my-project gcr.io/google_appengine/php:latest

To modify this command to stop the lockdown you simply add a new env var set to true: SKIP_LOCKDOWN_DOCUMENT_ROOT=true like this:
docker run -v /home/daniel/Repositories/my-project:/app -e DOCUMENT_ROOT=/app/public -e SKIP_LOCKDOWN_DOCUMENT_ROOT=true --name my-project gcr.io/google_appengine/php:latest

And that’s it! No more chmod when working locally allowing you to work in an App Engine like environment!

If this tip helped you, I’d love to hear from you. If you have any feedback or edits, just comment below.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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