1

I'm working on a PHP app in Google App Engine. I set the document_root to "public" in the yaml, but it's ignored by the server when I deploy the app.

This is my directory structure:

app engine:/
- public
  - good.php
  - index.php
- app.yaml
- bad.php
- php.ini

And this is the contect of my app.yaml:

runtime: php55
api_version: 1
threadsafe: true

runtime_config:
  document_root: public

handlers:
- url: /(.+\.php)$
  script: \1

- url: /.*
  script: index.php

What I expect to happen:

What actually happens:

How can I fix this? Am I missing something? Is something wrong with my document_root declaration in the yaml file?

Aegas
  • 31
  • 5

2 Answers2

2

You're mixing flexible environment configs in your standard environment app.yaml file.

The document_root is under runtime_config, which is a flexible environment configuration, not a standard environment one. There is no mention of such config in the standard environment app.yaml Reference.

Maybe of interest: How to tell if a Google App Engine documentation page applies to the standard or the flexible environment

In the standard environment you'll need to use the handlers configurations to achieve what you want.

And remember that their URL patterns are relative to the respective service's root directory which is where its app.yaml file exists. This is why your bad.php script is served OK (matching your first handler pattern). I'd also expect https://mysiteurl/good.php to give a 404 and https://mysiteurl/public/good.php to work OK (but I'm not very certain, I'm a python user, not a php one).

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
2

As Dan Cornilescu's answer pointed out. There's no such document_root directive for the standard enviroment yaml.

But I finally managed to achieve what I wanted by using the following YAML:

runtime: php55
api_version: 1
threadsafe: true

handlers:
- url: /(.+\.php)$
  script: public/\1

- url: /.*
  script: public/index.php

In this way, whatever url you browse, only things inside the "public" directory are accessed.

Aegas
  • 31
  • 5