App Engine Flex Environment PHP Runtime document root not found

2,024 views
Skip to first unread message

Yao Li

unread,
Apr 18, 2017, 7:40:29 PM4/18/17
to Google App Engine
I followed setting in the doc:

There is a index.php file in my project root folder (for example, my project name is project_folder, it's app in the doc), as the above doc, I don't have to change the document root in app.yaml, but it failed and has 500 when visit service.myproject.appspot.com (I deployed it as a service in GAE Flex environment, I tested deployment in standard environment and it shows 'Hello World' as expected, everything is same except runtime, env and service in the app.yaml).
 
I tried to define runtime_config: document_root as '/', or '/project_folder', neither of them work.

I even created a folder web under root folder and a index.php test file as follow in app.yaml, but it still doesn't find the index.php file.

runtime_config:
    document_root: web

How to define document_root correctly?

Takashi Matsuo

unread,
Apr 18, 2017, 9:32:59 PM4/18/17
to Google App Engine

Hi Yao,

If you put the index.php in the project root folder, you don't have to add the document_root.

Here is the minimum app:

```
$ tree
.
├── app.yaml
└── index.php

0 directories, 2 files
tmatsuo@t-glaptop:~/work/simplestapp$ cat index.php 
<?php

echo 'Hello world';

tmatsuo@t-glaptop:~/work/simplestapp$ cat app.yaml
env: flex
runtime: php
service: my-service
```

After deploying, I can access the app at https://my-service-dot-my-app.appspot.com/

If it returns 500 HTTP error, I suggest that you go to the Logging console at:

and see what's happening there.

Thanks!



--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/cbdc1aee-26ec-4a26-947e-11a1799c82f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Takashi Matsuo

unread,
Apr 19, 2017, 11:39:55 AM4/19/17
to Google App Engine

Hi Yao,

Also feel free to send the app to me if possible so that I can try to reproduce. I'm happy to debug it.

Thanks,
--
-- Takashi

Yao Li

unread,
Apr 19, 2017, 11:48:43 AM4/19/17
to Google App Engine
I found an error in the log, it complains "FastCGI sent in stderr: "PHP message: ALERT-SIMULATION - Unable to open logfile: /dev/stderr".

I did create a docker image for my business requirement (use own PHP framework on nginx) based on Google Cloud Platform php-nginx.

Yao Li

unread,
Apr 19, 2017, 12:04:36 PM4/19/17
to Google App Engine
There is an error in the log:

07:47:37.000 [error] 37#0: *7 FastCGI sent in stderr: "PHP message: ALERT-SIMULATION - Unable to open logfile: /dev/stderr (attacker '', file '/app/vendor/my_company/my_framework/my_file.php', line 143)
07:47:37.000 PHP message: PHP Warning: SIMULATION - php_uname() has been disabled for security reasons in /app/vendor/my_company/my_framework/my_file.php on line 143" while reading response header from upstream, client: 172.18.0.3, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "monitor-dot-my-company.appspot.com"
07:47:41.770 GET 500 35 B 33 ms Chrome 57 /

It calls php_uname() in line 143 and php_uname is disabled, but I do enable it php.ini:
google_app_engine.enable_functions = "php_uname"

But it still failed with 500 when access root (/).



On Wednesday, April 19, 2017 at 8:39:55 AM UTC-7, Takashi Matsuo (Google) wrote:

Takashi Matsuo

unread,
Apr 19, 2017, 12:57:03 PM4/19/17
to google-a...@googlegroups.com
Hi Yao,

On Wed, Apr 19, 2017 at 8:48 AM Yao Li <y...@sazze.com> wrote:
I found an error in the log, it complains "FastCGI sent in stderr: "PHP message: ALERT-SIMULATION - Unable to open logfile: /dev/stderr".

I did create a docker image for my business requirement (use own PHP framework on nginx) based on Google Cloud Platform php-nginx.



Glad you figured it out, although it doesn't seem like the real issue. The 'ALERT_SIMULATION' indicates that the suhosin extension is just emitting a warning, and it shouldn't stop the app.

Anyways, do you mind telling me what was the required change for you? Maybe we can incorporate your change so that you will be able to just use our image.

Thanks!
 

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 19, 2017, 1:10:15 PM4/19/17
to Google App Engine
I add flag -m to preserve environment variable (composer_auth which has gitlab token to composer install private repos) in composer.sh line 81:

Takashi Matsuo

unread,
Apr 19, 2017, 3:17:46 PM4/19/17
to Google App Engine

Thanks! That makes sense. I will make the change soon and let you know when it's done!


For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 19, 2017, 4:39:59 PM4/19/17
to Google App Engine
BTW, XCache is used in my company PHP framework and it caused failure without any error message when access the home page (root /), it works after comment out the code with XCache.

Takashi Matsuo

unread,
Apr 19, 2017, 5:11:54 PM4/19/17
to Google App Engine

Hi Yao,

Thanks for the report. My understanding is XCache is for opcode caching, and the last release is 20140918.
We're using the standard `opcache` zend extension, and it has been working pretty well for us.

The runtime already has the extension, so only you need is to put php.ini with the following content.

```php.ini
zend_extension=opcache.so
```

Please try it out and let us know how it works for you!

Thanks,



For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 19, 2017, 7:06:28 PM4/19/17
to Google App Engine
I used XCache in GAE standard environment (PHP 5.5) and it works, but it doesn't in flex one (PHP 5.6).

Takashi Matsuo

unread,
Apr 20, 2017, 1:05:15 AM4/20/17
to Google App Engine

Hi Yao,

So adding to my previous e-mail, the `opcache` zend extension is also an extension for opcode caching. XCache  used to be a viable option for opcode caching, but it is not very actively maintained.

I recommend that you try using opcache, and see if there's enough performance gain.

Speaking of performance, the runtime supports PHP 7.0.x and 7.1.x, and they are quite fast. Is migrating to newer PHP an option for you?

Thanks,



For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 20, 2017, 11:56:24 AM4/20/17
to Google App Engine
I do have the plan to upgrade to 7.0+, but current system is in 5.6 and I have to figure out it.

Actually it's not XCache issue, it's Memcache issue.

My company PHP framwork use Memcache for session handler and it works in standard environment, but failed when I do new \Memcache().

I cmd + click to go to the class definition which is in php.jar/stubs/memcache/memcache.php in IDE, but the program stopped when execute new \Memcache() in GAE flex environment (php).

Yao Li

unread,
Apr 20, 2017, 2:21:29 PM4/20/17
to Google App Engine
As the following doc, Memcache is not available at GAE flex environment.

https://cloud.google.com/appengine/docs/flexible/php/upgrading

Takashi Matsuo

unread,
Apr 20, 2017, 2:34:02 PM4/20/17
to Google App Engine

The `Memcache` class comes with `memcache` extension.
To enable `memcache` extension on App Engine flex, you can add a dependency in your `composer.json`.

```
$ composer require 'ext-memcache:*'
```
Then our runtime will automatically enable the memcache extension for you.

The memcache service for App Engine Flex is currently Alpha.

You can request access at:

Or you can use 3rd party service like redislab:

One more note around Memcache.

There are two extensions for using memcached; `memcache` and `memcached` extensions. Yeah it's confusing, but in short, the `memcache` is an old one, and not actively maintained. On our runtime, we only provide `memcached` extension for PHP 7.0.x and PHP 7.1.x. So if you have a plan to migrate to PHP 7, I recommend that you look into `memcached` extension, instead of `memcache`.

Of course you can do:

```
$ composer require 'ext-memcached:*'
```
To enable the extension on our runtime.

Thanks!


For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 20, 2017, 5:41:31 PM4/20/17
to Google App Engine
It works like a charm after add memcache extension, thanks!

In the very beginning, I deployed a default service in standard environment (my-company.appspot.com) and then a monitor service in flex environment now (monitor-dot-my-company.appspot.com).

1. The default service could access Cloud SQL in standard environment before, but monitor service cannot in flex environment now.

I did configure to authorize the app in Google Cloud Platform dashboard, SQL page, Access Control label, does it only work for standard environment? (standard and flex in my case have same ip)

2. php echo and Aura::infoLog (Aura is my company PHP framework) don't print anything out in flex env and they do work in standard one, is there specific log or debug tool in flex environment?

Takashi Matsuo

unread,
Apr 20, 2017, 7:05:05 PM4/20/17
to google-a...@googlegroups.com

Hi Yao,

On Thu, Apr 20, 2017 at 2:41 PM Yao Li <y...@sazze.com> wrote:
It works like a charm after add memcache extension, thanks!

Glad to hear!
 

In the very beginning, I deployed a default service in standard environment (my-company.appspot.com) and then a monitor service in flex environment now (monitor-dot-my-company.appspot.com).

1. The default service could access Cloud SQL in standard environment before, but monitor service cannot in flex environment now.

I did configure to authorize the app in Google Cloud Platform dashboard, SQL page, Access Control label, does it only work for standard environment? (standard and flex in my case have same ip)

On App Engine Flex, you have to add Cloud SQL's connection string in your app.yaml like:
```
beta_settings:
    cloud_sql_instances: "CONNECTION_NAME"
```
You should be able to get the connection name on the Cloud SQL section of the Console.
 

2. php echo and Aura::infoLog (Aura is my company PHP framework) don't print anything out in flex env and they do work in standard one, is there specific log or debug tool in flex environment?

We're working hard on the Logging and Tracing library, and they're getting really close. I'll keep you updated. Our current plan for Logging is to provide a PSR-3 compatible Logger, with Error Reporting capability. Stay tuned!

Well, so what's the current status?
On App Engine flex, standard out and standard err are captured and should be available on the Logging console. You may need to select the log name selector to choose stdout and stderr. Unfortunately, syslog() is not supported on App Engine Flex. What low level function does Aura use under the cover?

Thanks,
 

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 21, 2017, 12:52:31 PM4/21/17
to Google App Engine
1 Cloud SQL Connection. I set cloud_sql_instances connection name but it doesn't work. I tried use its actual IP or 'localhost' as host name, neither of them work.

2. Logging. It has some issue to open logfile:/dev/stderr as the following log file, Aura use several levels, info, warning, error.

08:45:05.000 2017/04/21 15:45:05 [error] 37#0: *54 FastCGI sent in stderr: "PHP message: ALERT-SIMULATION - Unable to open logfile: /dev/stderr (attacker '', file '/app/vendor/my_company/aura/Aura.php', line 143)

08:45:05.000 PHP message: PHP Warning: SIMULATION - php_uname() has been disabled for security reasons in /app/vendor/my_company/aura/Aura.php on line 143" while reading response header from upstream, client: 172.*.*.3, server: , request: "POST /Users/loginAction HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "monitor-dot-my-company.appspot.com", referrer: "https://monitor-dot-my-company.appspot.com/Users/signIn"

Takashi Matsuo

unread,
Apr 21, 2017, 2:13:52 PM4/21/17
to Google App Engine

Hi Yao,

1 Cloud SQL Connection. I set cloud_sql_instances connection name but it doesn't work. I tried use its actual IP or 'localhost' as host name, neither of them work.

Do you use Cloud SQL first generation? If so, unfortunately it's not supported on App Engine Flex.

Here is the document for how to connect to Cloud SQL second generation from App Engine Flex:

Note that you need to enable `sqladmin` API on your project. You can use this link to enable it:

Also you have to explicitly use a user and the password, whereas App Engine Standard will automatically use root and the password is bypassed.

Re: /dev/stderr

I think you can use the constant STDERR like:
```
fwrite(STDERR, "message" . PHP_EOL);
```





For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Takashi Matsuo

unread,
Apr 21, 2017, 11:00:38 PM4/21/17
to Google App Engine

Hi Yao,

Sorry! I was wrong.  The constants STDERR is only available for CLI SAPI.
Also, the current php-fpm.conf just throws the logs on STDERR away (my fault).

We will fix this early next week, but for a time being, you can put a file named php-fpm.conf in the project root with the following:
```
error_log = /dev/stderr
```

Then the following code will work:
```
$stderr = fopen('php://stderr', 'w');
fwrite($stderr, 'Log to stderr' . PHP_EOL);
```

Also `error_log()` works too.

Sorry, and thanks!

--
-- Takashi

Yao Li

unread,
Apr 22, 2017, 2:29:19 AM4/22/17
to Google App Engine

1. I use Second Generation Instance for Cloud SQL in flex environment, did enable 'sqladmin' on my project.

The cloud sql instance log shows:

10:12:52.4252017-04-21T17:12:52.425362Z 7115 [Note] Aborted connection 7115 to db: 'f_s' user: 'f-s' host: '66.*.*.210' (Got timeout reading communication packets)


2. Logging
It complains error after put a file named php-fpm.conf in the project root.
[22-Apr-2017 06:07:42] ERROR: [/opt/php/etc/php-fpm-user.conf:1] unknown entry 'error_log'
[22-Apr-2017 06:07:42] ERROR: Unable to include /opt/php/etc/php-fpm-user.conf from /opt/php/etc/php-fpm.conf at line 1
[22-Apr-2017 06:07:42] ERROR: failed to load configuration file '/opt/php/etc/php-fpm.conf'
[22-Apr-2017 06:07:42] ERROR: FPM initialization failed
2017-04-22 06:07:42,142 INFO spawned: 'php-fpm' with pid 41
2017-04-22 06:07:42,170 INFO exited: php-fpm (exit status 78; not expected)
2017-04-22 06:07:43,171 INFO gave up: php-fpm entered FATAL state, too many start retries too quickly
 

Takashi Matsuo

unread,
Apr 22, 2017, 10:40:02 AM4/22/17
to google-a...@googlegroups.com
Hi Yao,

On Fri, Apr 21, 2017 at 11:29 PM Yao Li <y...@sazze.com> wrote:

1. I use Second Generation Instance for Cloud SQL in flex environment, did enable 'sqladmin' on my project.

The cloud sql instance log shows:

10:12:52.4252017-04-21T17:12:52.425362Z 7115 [Note] Aborted connection 7115 to db: 'f_s' user: 'f-s' host: '66.*.*.210' (Got timeout reading communication packets)



Looks like you're using the IP address? On App Engine Flex, you can use the local socket.

```app.yaml
env: flex
runtime: php

beta_settings:
  cloud_sql_instances: "CONNECTION_NAME"
```
Replace the CONNECTION_NAME with your Cloud SQL connection name. This beta_settings will create a local socket for you on the VM.

Then in your code, you use the connection name again:

```
$pdo = new PDO(
    'mysql:dbname=DB_NAME;unix_socket=/cloudsql/CONNECTION_NAME',
    'DB_USERNAME',
    'DB_PASSWORD'
);
```
Replace the DB_NAME, CONNECTION_NAME, DB_USERNAME, and DB_PASSWORD respectively, then you should be good to go.
 
2. Logging
It complains error after put a file named php-fpm.conf in the project root.
[22-Apr-2017 06:07:42] ERROR: [/opt/php/etc/php-fpm-user.conf:1] unknown entry 'error_log'
[22-Apr-2017 06:07:42] ERROR: Unable to include /opt/php/etc/php-fpm-user.conf from /opt/php/etc/php-fpm.conf at line 1
[22-Apr-2017 06:07:42] ERROR: failed to load configuration file '/opt/php/etc/php-fpm.conf'
[22-Apr-2017 06:07:42] ERROR: FPM initialization failed
2017-04-22 06:07:42,142 INFO spawned: 'php-fpm' with pid 41
2017-04-22 06:07:42,170 INFO exited: php-fpm (exit status 78; not expected)
2017-04-22 06:07:43,171 INFO gave up: php-fpm entered FATAL state, too many start retries too quickly

Oops! My bad. You need the `global` section too.
```
[global]
error_log = /dev/stderr
```
 
Thanks!

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 24, 2017, 11:31:40 AM4/24/17
to Google App Engine
1. Cloud SQL
It doesn't expose mysql unix_socket in the company framework but host, I did try to config host as the cloud sql instance ip or 'localhost' for host parameter, but nether of them work. Can I use host (cloud sql instance ip) for mysql configuration in this case or only unix_socket works?

2. Logging
It doesn't print anything in Logs View even after add [global] in php-fpm.conf

Yao Li

unread,
Apr 24, 2017, 12:39:32 PM4/24/17
to Google App Engine
I want to install New Relic agent in the custom image (php-nginx) to monitor app level performance, as the code in php-docker (deb-package-builder) repo, GAE flex env is based on Debian, is there any libs or scripts to install software (new relic) in this environment? 

https://docs.newrelic.com/docs/agents/php-agent/getting-started/introduction-new-relic-php

Takashi Matsuo

unread,
Apr 24, 2017, 1:54:47 PM4/24/17
to Google App Engine

Hi Yao,

1. CloudSQL

Yes, we recommend that you use the unix socket.

If you're using mysql_connect, you may be able to use 'localhost:/cloudsql/CONNECTION_NAME' as the host name.

```php.ini
extension=mysql.so
sql.safe_mode=false
```
Then:
$db = mysql_connect('localhost:/cloudsql/CONNECTION_NAME', 'USER', 'PASSWORD');


If you're using mysqli_connect, you can specify the default socket in php.ini.

```php.ini
mysqli.default_socket= '/cloudsql/CONNECTION_NAME' 
```

$db = mysqli_connect('localhost', 'USER', 'PASSWORD', 'DB');

2. Log

I can not reproduce your issue. Here is a simple app trying to repro, but I see the logs in the logs viewer.

```app.yaml
runtime: php
env: flex
```

```php-fpm.conf
[global]
error_log = /dev/stderr
```

```index.php
<?php

$fp = fopen('php://stderr', 'w');

fwrite($fp, 'Log to stderr' . PHP_EOL);
fclose($fp);

error_log('Log with error_log()');

echo 'Sent a log to stderr, and error_log';
```

You may have to choose the logname 'stderr' in the logging console to see those logs.

3. Extension

Currently you have to use the custom runtime, and yeah the Dockerfile for deb-package-builder will guide you which apt packages are need for compiling extensions.

Thanks!

-- Takashi


For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 24, 2017, 6:28:13 PM4/24/17
to Google App Engine
1. CloudSQL

I did connect successfully by setting default socket in php.ini. Thanks.

I copied data from a 1st generation cloud sql instance to a 2nd one, data is exactly same but the size is doubled, is it because of the 2nd generation one specific attribute?

2. Log
I did choose the logname 'stderr' in the logging console and it only prints out the content inside fwrite(), like 'Log to stderr' in your example. Anyway, it can log now.

Takashi Matsuo

unread,
Apr 24, 2017, 9:32:12 PM4/24/17
to Google App Engine

Hi Yao,

I copied data from a 1st generation cloud sql instance to a 2nd one, data is exactly same but the size is doubled, is it because of the 2nd generation one specific attribute?

Sorry I'm not an expert on that topic. Maybe you can try google-cloud-sql-discuss list?

Glad to hear you could connect to Cloud SQL and see the logs!

BTW, we're going to start alpha tester program for the new logging library on App Engine Flex PHP.
Are you interested in testing it out?

Thanks,




For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 24, 2017, 11:29:28 PM4/24/17
to Google App Engine
I'm interested in App Engine Flex PHP alpha version and did fill the register form but have not received any response.

Takashi Matsuo

unread,
Apr 24, 2017, 11:45:36 PM4/24/17
to google-a...@googlegroups.com, Justin Beckwith
Adding our PM

On Mon, Apr 24, 2017 at 8:29 PM Yao Li <y...@sazze.com> wrote:
I'm interested in App Engine Flex PHP alpha version and did fill the register form but have not received any response.

I think you are referring to the alpha program of the memcache service. If that's the case, Justin knows more about the program.

What I was saying is for our new logging library :)

The new logging library will provide 1) PSR3 interface, 2) automatic capturing Fatal errors and unhanded Exceptions to Stackdriver Error Rerporting, 3) high throughput and low latency.

Let me know if you're interested in.

-- Takashi
 

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 25, 2017, 12:17:04 AM4/25/17
to Google App Engine, beck...@google.com
Yes, I'm interested in the alpha version and new log service.

I tried Redis Lab Memcache, it doesn't support memcache, only memcached?
Adding our PM

Hi Yao,

<blockquote class="gmail_quote" style="margin:0;margin-le

Takashi Matsuo

unread,
Apr 25, 2017, 12:31:54 AM4/25/17
to Google App Engine, beck...@google.com
Hi Yao,
Alright, I've just sent you the instructions.

Thanks!


For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 25, 2017, 11:39:21 AM4/25/17
to Google App Engine, beck...@google.com
Hi Takashi,

This instruction is only about Logging, doesn't include memcache, right?


On Monday, April 24, 2017 at 9:31:54 PM UTC-7, Takashi Matsuo (Google) wrote:
Hi Yao,
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;

Takashi Matsuo

unread,
Apr 25, 2017, 11:42:17 AM4/25/17
to google-a...@googlegroups.com
Hi Yao,

Yes, you are right.

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 25, 2017, 12:25:20 PM4/25/17
to Google App Engine
Hi Takashi,

Could you ask Justin to send me a test (alpha) version including memcache?

As the doc, Redis Lab Memcache supports memcached, not memcache.

Takashi Matsuo

unread,
Apr 25, 2017, 12:47:14 PM4/25/17
to Google App Engine

Hi Yao,

I asked a PM who is responsible for it (it turned out it's not Justin). I will reply you off-thread.

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 25, 2017, 4:11:25 PM4/25/17
to Google App Engine
Hi Takashi,

I installed New Relic Agent in custom php-nginx docker image but it doesn't show any data and I'm investigating it.

Is there a way to do restart (nginx, php-fpm, httpd, etc.) and ls (look up new relic extension in specific directory) in GAE Flex env?

Right now I make a new image and re-deploy to restart but seems not working.
<blockquote class="gmail_quote" style

Takashi Matsuo

unread,
Apr 25, 2017, 7:10:59 PM4/25/17
to Google App Engine

Hi Yao,

You can ssh into the VM; Go to the Cloud Console, and App Engine -> instances -> ssh.

Once ssh into it, you can go into the docker container:

```
sudo docker exec -t -i gaeapp /bin/bash
```

Then you can restart everything in the Docker container by:
```
kill -HUP 1
```


--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 25, 2017, 7:41:01 PM4/25/17
to Google App Engine
I cannot find ssh button (as top right corner in screenshot), is it because of permission or some other reason?

<blockquote class="gmail_quo

Yao Li

unread,
Apr 26, 2017, 11:52:51 AM4/26/17
to Google App Engine
I can see ssh button in Firefox but Chrome, it should be a Chrome issue.

I went to docker container gaeapp, but I didn't see any docker container is running (empty after docker ps), no images neither (empty after docker images). But I tried kill -HUP 1 and it does affect the application (shut down).


```
sudo docker exec -t -i gaeapp /bin/bash
```

Do I need replace 'gaeapp' to my project id or service name?


On Thu, Apr 20, 2017 at 2:41 PM Yao Li <y...@sazze.com> wrote:<br

Takashi Matsuo

unread,
Apr 26, 2017, 2:26:36 PM4/26/17
to Google App Engine

Hi Yao,

According to "Availability: dynamic", it looks to me that you look at the App Engine Standard instance. Make sure you choose the Flex version.

The VM runs a container named `gaeapp` for your application. Did you do `docker ps`  in the application container?

I'm happy to explain this process on a video call or something if it does make sense to you.

-- Takashi

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 26, 2017, 2:37:11 PM4/26/17
to Google App Engine
Ok, we can talk with Hangout.

</

Yao Li

unread,
Apr 26, 2017, 5:31:40 PM4/26/17
to Google App Engine
Hi Takashi,

I'm installing New Relic PHP agent based on php-nginx docker image, it does finish all commands in Dockerfile but not show New Relic in phpinfo() page (phpinfo() will show New Relic module if installed successfully), how to ensure run the installation command with root user in bash shell or Dockerfile? 

I tried both of following cases, but neither of them work.

Code 0:
Dockerfile
```
RUN su www-data -c "newrelic-install install"
```

Code 1:
install_new_relic.sh (it complains error if add sudo or su before newrelic-install)
```
newrelic-install install
```

Logs:
+ apt-get install -yq newrelic-php5
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
  newrelic-daemon newrelic-php5-common
The following NEW packages will be installed:
  newrelic-daemon newrelic-php5 newrelic-php5-common
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 8634 kB of archives.
After this operation, 25.9 MB of additional disk space will be used.
Get:1 http://apt.newrelic.com/debian/ newrelic/non-free newrelic-php5-common all 7.2.0.191 [26.2 kB]
Get:2 http://apt.newrelic.com/debian/ newrelic/non-free newrelic-daemon amd64 7.2.0.191 [2810 kB]
Get:3 http://apt.newrelic.com/debian/ newrelic/non-free newrelic-php5 amd64 7.2.0.191 [5798 kB]
Preconfiguring packages ...
Fetched 8634 kB in 1s (5053 kB/s)
Selecting previously unselected package newrelic-php5-common.
(Reading database ... 14536 files and directories currently installed.)
Preparing to unpack .../newrelic-php5-common_7.2.0.191_all.deb ...
Unpacking newrelic-php5-common (7.2.0.191) ...
Setting up newrelic-php5-common (7.2.0.191) ...
Selecting previously unselected package newrelic-daemon.
(Reading database ... 14549 files and directories currently installed.)
Preparing to unpack .../newrelic-daemon_7.2.0.191_amd64.deb ...
Unpacking newrelic-daemon (7.2.0.191) ...
Processing triggers for systemd (215-17+deb8u6) ...
Setting up newrelic-daemon (7.2.0.191) ...
Processing triggers for systemd (215-17+deb8u6) ...
Selecting previously unselected package newrelic-php5.
(Reading database ... 14557 files and directories currently installed.)
Preparing to unpack .../newrelic-php5_7.2.0.191_amd64.deb ...
Unpacking newrelic-php5 (7.2.0.191) ...
Setting up newrelic-php5 (7.2.0.191) ...
Please run newrelic-install as root to complete installation.
+ newrelic-install install
 ---> 1fef98f9ee82
Removing intermediate container 42cf882e3357
<blockquote class="gmail_quote" style="margin:0;margin-left:

Takashi Matsuo

unread,
Apr 26, 2017, 5:44:11 PM4/26/17
to Google App Engine

Hi Yao,

According to their docs, I think you need to use this method:

Unfortunately we're not using the debian's official apt package.


--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 26, 2017, 11:28:29 PM4/26/17
to Google App Engine
I want to check the log file in the docker container, but none of vi, vim, nano works. Do I need to install text editor in the docker image or some other way to view the content?

Or use scp to copy to my mac?

Takashi Matsuo

unread,
Apr 26, 2017, 11:33:55 PM4/26/17
to Google App Engine

I often do:
```
apt-get update && apt-get install -y vim less
```
If you're using runtime:custom, maybe you can install them during development phase

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 28, 2017, 12:10:03 PM4/28/17
to Google App Engine
Hi Takashi,

I did get New Relic installed successfully, thanks!

The current issue is 404 for API request from mobile app or Postman software.

I have the default service (f-s.appspot.com) in standard environment and its API service works well, I copied code to monitor service (monitor-dot-f-s.appspot.com) which is deployed to flex env and it doesn't work now.

I wonder there are 2 reasons:
1. security certificate
2. memcache for session handler (used when initialize basic API controller, it can pass the initialization but session doesn't work, actually REST api doesn't need session)

API in default service works and reason 1 should not be the problem, how do you think about the 2nd reason or some other reasons?

BTW, I still have not received the alpha version for memcache from the PM as you mentioned, maybe I have to upgrade to PHP 7+ and use memcached.
$stderr = fopen('php://stderr', &#3

Takashi Matsuo

unread,
Apr 28, 2017, 4:52:22 PM4/28/17
to google-a...@googlegroups.com
Hi Yao,

On Fri, Apr 28, 2017 at 9:10 AM Yao Li <y...@sazze.com> wrote:
Hi Takashi,

I did get New Relic installed successfully, thanks!

Great :)
 

The current issue is 404 for API request from mobile app or Postman software.

I have the default service (f-s.appspot.com) in standard environment and its API service works well, I copied code to monitor service (monitor-dot-f-s.appspot.com) which is deployed to flex env and it doesn't work now.

I wonder there are 2 reasons:
1. security certificate
2. memcache for session handler (used when initialize basic API controller, it can pass the initialization but session doesn't work, actually REST api doesn't need session)

API in default service works and reason 1 should not be the problem, how do you think about the 2nd reason or some other reasons?

Sorry, but I can not tell without knowing your code.

Re: session, I wrote the datastore session handler:

It will add some more latency, but only you have to do is to enable the datastore API. Please consider using this if it's ok to add some latency.
 

BTW, I still have not received the alpha version for memcache from the PM as you mentioned, maybe I have to upgrade to PHP 7+ and use memcached.


I talked with the PM again today, I can not promise anything though.

Thanks,
 
--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
Apr 28, 2017, 6:50:41 PM4/28/17
to Google App Engine
I found the possible reason:

I defined routing in app.yaml and it works for standard environment but flex env, it seems flex env doesn't support handlers for routing.

handlers:
- url: /v\d+/.*
script: api/index.php
secure: always

Yao Li

unread,
Apr 28, 2017, 7:51:26 PM4/28/17
to Google App Engine
Two questions:
1.  flex env doesn't support handlers for routing?
2. Can I migrate traffic from default service (on standard environment) to monitor one (on flex)? Or update monitor to default service?
Hi Yao,

<div dir=

Yao Li

unread,
Apr 28, 2017, 7:57:11 PM4/28/17
to Google App Engine
btw, default service (on standard environment) is using 1st gen cloud sql instance, monitor one (on flex) is using 2nd gen one.

Yao Li

unread,
May 1, 2017, 11:46:00 AM5/1/17
to Google App Engine
How about deploying without specifying service name in app.yaml? It will replace the current default service, right?

Takashi Matsuo

unread,
May 1, 2017, 12:46:20 PM5/1/17
to Google App Engine

Hi Yao,

1.  flex env doesn't support handlers for routing?

No Flex doesn't support handlers. Instead you can put a partial config file for nginx. Put a file named nginx-app.conf. The default configuration is as follows:

```
location / {
  # try to serve files directly, fallback to the front controller
  try_files $uri /index.php$is_args$args;
}
```

Can I migrate traffic from default service (on standard environment) to monitor one (on flex)? Or update monitor to default service?

AFAIK, there's no way to do that, but instead you can use versions.

Remove `service` from the app.yaml (so it's default service), and deploy with `--version` option as follows:

```
$ gcloud app deploy --version=api-flex --no-promote --no-stop-previous-version
```

You can migrate traffic between versions.

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
May 1, 2017, 1:28:14 PM5/1/17
to Google App Engine
1. I have to install New Relic agent on instance manually with script currently after ssh, is there a way (API, script or something else) to install the following script automatically?

```
wget -r -l1 -nd -A"linux.tar.gz" https://download.newrelic.com/php_agent/release/
gzip -dc newrelic*.tar.gz | tar xf -
cd newrelic-php5*
rm -f /opt/php56/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20131226/newrelic.so
cp ./agent/x64/newrelic-20131226.so /opt/php56/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20131226/newrelic.so
cp ./daemon/newrelic-daemon.x64 /usr/bin/newrelic-daemon

sed -i -e 's/"REPLACE_WITH_REAL_KEY"/yourLicenseKey/g' ./scripts/newrelic.ini.template
sed -i -e 's/PHP Application/yourApplicationName/g' ./scripts/newrelic.ini.template
cp ./scripts/newrelic.ini.template /opt/php56/lib/ext.enabled:/opt/php56/lib/conf.d:/app/newrelic.ini

/usr/bin/newrelic-daemon start
```
2. I saw there are 2 or 3 instances in flex env, it seems I have to install New Relic (NR) agent on each one, right? (because every instance is independent to hold the app, I didn't see NR agent on the 1st instance if I only installed on 2nd or 3rd)

Takashi Matsuo

unread,
May 1, 2017, 3:47:45 PM5/1/17
to google-a...@googlegroups.com

Hi Yao,

FYI, we released a new Runtime image which should capture the logs on stderr by default.

On Mon, May 1, 2017 at 10:28 AM Yao Li <y...@sazze.com> wrote:
1. I have to install New Relic agent on instance manually with script currently after ssh, is there a way (API, script or something else) to install the following script automatically?

Use runtime:custom and add required piece in your Dockerfile, except for the `/usr/bin/newrelic-daemon start` line.

Then have a file named `additional-supervisord.conf` with the following:

```
[program:newrelic-daemon]
command = /usr/bin/newrelic-daemon -f
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes=0
user = root
autostart = true
autorestart = true
priority = 5
stopwaitsecs = 20
```

I don't know if the newrelic daemon requires root, so this configuration runs as root in this example, but please use another account if possible.

I haven't tested it myself, but technically it should work.

-- Takashi

 

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
May 4, 2017, 10:57:49 AM5/4/17
to Google App Engine
I add New Relic install script in Dockerfile of app level and it works, thanks.

The cron job has 403 issue after I deploy the app in GAE flex env as default service, it works well (200) previously with app in GAE standard env.
Do I need do some configuration for flex one?
Hi Yao,

Thanks!

</di

Yao Li

unread,
May 4, 2017, 11:03:18 AM5/4/17
to Google App Engine
btw, I did add cron job routing when initializing app in flex env, the cron routes are defined in app.yaml (handler part) for standard env.

Takashi Matsuo

unread,
May 4, 2017, 1:25:21 PM5/4/17
to Google App Engine

Hi Yao,

Cron works for me on my Flex app.

Can you show your cron.yaml, and app.yaml?

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
May 4, 2017, 3:13:05 PM5/4/17
to Google App Engine
cron.yaml
cron:
- description: check USPS Scanned every 4 hours
url: /Cron/checkUSPSScanned
schedule: every 4 hours
retry_parameters:
min_backoff_seconds: 5
max_doublings: 5

- description: check USPS Scanned every 4 hours (batch 2)
url: /Cron/checkUSPSScannedBatch2
schedule: every 4 hours
retry_parameters:
min_backoff_seconds: 5
max_doublings: 5

- description: check Delivered every 4 hours
url: /Cron/checkDelivered
schedule: every 4 hours
retry_parameters:
min_backoff_seconds: 5
max_doublings: 5

- description: check Delivered every 4 hours (batch 2)
url: /Cron/checkDeliveredBatch2
schedule: every 4 hours
retry_parameters:
min_backoff_seconds: 5
max_doublings:

app.yaml
runtime: custom
env: flex


handlers:
- url: /v\d+/.*
script: api/index.php
secure: always

- url: /.*
script: index.php
secure: always

- url: /Cron/.*
script: index.php
secure: always
login: admin

resources:
cpu: 0.5
memory_gb: 1.0
disk_size_gb: 10

env_variables:
WHITELIST_FUNCTIONS: phpinfo

beta_settings:
cloud_sql_instances: "f-s:us-central1:flex-prod-usc-sql-2"

\classes\cron\Routes.php
namespace classes\cron;

class Routes {
public static $default = array(
'~^/Cron/checkUSPSScanned?(\?.*)?$~' => array('\classes\controllers\Cron', 'checkUSPSScanned'),
'~^/Cron/checkUSPSScannedBatch2?(\?.*)?$~' => array('\classes\controllers\Cron', 'checkUSPSScannedBatch2'),
'~^/Cron/checkDelivered?(\?.*)?$~' => array('\classes\controllers\Cron', 'checkDelivered'),
'~^/Cron/checkDeliveredBatch2?(\?.*)?$~' => array('\classes\controllers\Cron', 'checkDeliveredBatch2')
);
}

Takashi Matsuo

unread,
May 4, 2017, 3:35:39 PM5/4/17
to Google App Engine

Hi Yao,

I think your handlers are protected only for authorized users, right?

On App Engine flex, it changed how to secure your cron handlers.
Check $_SERVER['HTTP_X_APPENGINE_CRON'] and if it's true, the requests are coming from App Engine cron service.


For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
May 4, 2017, 4:18:09 PM5/4/17
to Google App Engine
Yes, it's for authorized users and worked for standard env, handler part doesn't work for flex and I added routes file.

As the log, it should come from App Engine.

Do I need remove cron config part in app.yaml or even delete the whole handler setting?


03:20:40.199 GET 403 162 B 0 ms AppEngine-Google; (+http://code.google.com/appengine) /Cron/checkDeliveredBatch2
130.211.1.37 - "GET /Cron/checkDeliveredBatch2" 403 162 "-" "AppEngine-Google; (+http://code.google.com/appengine)"
{
  insertId: "9.......l"
  jsonPayload: {
    trace: "$traceId"
    latencySeconds: "0.000"
    time: null
  }
  httpRequest: {
    requestMethod: "GET"
    requestUrl: "/Cron/checkDeliveredBatch2"
    status: 403
    responseSize: "162"
    userAgent: "AppEngine-Google; (+http://code.google.com/appengine)"
    remoteIp: "1...2...1...37"
    referer: "-"
  }
  resource: {
    type: "gae_app"

    labels: {…}
  }
  timestamp: "2017-05-04T10:20:40.199761605Z"
  labels: {
  }
  logName: "projects/f-s/logs/appengine.googleapis.com%2Fnginx.request"
}

On Thursday, May 4, 2017 at 12:35:39 PM UTC-7, Takashi Matsuo (Google) wrote:

Hi Yao,

Hi Yao,

Hi Yao,
</

Takashi Matsuo

unread,
May 4, 2017, 4:27:38 PM5/4/17
to Google App Engine

Hi Yao,

App Engine Flex doesn't support the handler section in app.yaml.
I think you're getting 403 because you're also restricting your cron handlers in your code somewhere. Can you do a quick code review on the cron handler, and change it to check the $_SERVER value as I mentioned?

Thanks,

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Yao Li

unread,
May 5, 2017, 1:58:37 PM5/5/17
to Google App Engine
You are right, I found the code to check $_SERVER['HTTP_X_APPENGINE_CRON']

public function before() {
if ($_SERVER['HTTP_X_APPENGINE_CRON'] != 'true') {
a\Error::raiseHttp403();
}
}

It complains with 403 which means it's not from app engine? But I'm sure it's from app engine flex env and it should set the value as true, right?

Takashi Matsuo

unread,
May 5, 2017, 2:36:18 PM5/5/17
to Google App Engine

Do you have any other place to return 403 in your cron code path?

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Takashi Matsuo

unread,
May 5, 2017, 5:57:20 PM5/5/17
to Google App Engine

Sorry sent it too early...

Do you have any other place to return 403 in the code path in your cron handler?
Your logic seems fine. I suspect that there might be another check for signed in state of the user, and now it gives you 403.

On Fri, May 5, 2017 at 11:35 AM Takashi Matsuo <tma...@google.com> wrote:

Do you have any other place to return 403 in your cron ?
--
-- Takashi

Yao Li

unread,
May 8, 2017, 4:19:44 PM5/8/17
to Google App Engine
Yes, I found one (403 check) before accessing static file and I will figure out what happened there.

Yao Li

unread,
May 22, 2017, 6:46:58 PM5/22/17
to Google App Engine
Is there a way to config cron job for specific service? (for example, I have 3 services, www, default, custom, they use different databases, how can I run a cron job only for service custom?)

Yao Li

unread,
May 23, 2017, 1:17:18 AM5/23/17
to Google App Engine
I investigated 403 check before accessing static file but there is no problem there.

The only code to check 403 is the before() function which is executed before run cron job, but it didn't print out the debug code I added in the before() function, there is only one line log:

21:24:22.536GET403162 B0 msAppEngine-Google; (+http://code.google.com/appengine)/Cron/myFunction

Yao Li

unread,
May 23, 2017, 11:36:25 AM5/23/17
to Google App Engine
I removed login:admin in app.yaml and it works for cron jobs.

Is there anyway to run cron jobs for specific service? (for example, I have 3 services, www, default, custom, they use different databases, how can I run a cron job only for service custom?)
<blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding

Takashi Matsuo

unread,
May 26, 2017, 11:03:32 PM5/26/17
to Google App Engine

Hi Yao,

I think you can use dispatch file or `target` in `cron.yaml`.
Feel free to let us know if our Flex documentation doesn't help you find solutions.

Thanks,

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.

For more options, visit https://groups.google.com/d/optout.
--
-- Takashi

Vick Khera

unread,
Nov 20, 2017, 12:18:06 PM11/20/17
to Google App Engine
On Thursday, April 20, 2017 at 2:34:02 PM UTC-4, Takashi Matsuo (Google) wrote:

There are two extensions for using memcached; `memcache` and `memcached` extensions. Yeah it's confusing, but in short, the `memcache` is an old one, and not actively maintained. On our runtime, we only provide `memcached` extension for PHP 7.0.x and PHP 7.1.x. So if you have a plan to migrate to PHP 7, I recommend that you look into `memcached` extension, instead of `memcache`.

Of course you can do:

```
$ composer require 'ext-memcached:*'
```
To enable the extension on our runtime.

This confuses me a little. You say the flex environment provides the memcached extension, yet I also have to include it in my composer. If I don't require it in composer (so it installs into the vendor directory), is the Memcached extension just not available to my application? Would the symptom of that be a very long delay in the code execution requesting the module?
 
Reply all
Reply to author
Forward
0 new messages