Search code examples
google-app-enginegoogle-cloud-platformcomposer-phpgcloudapp-engine-flexible

post-install-cmd not working in Google App Engine Flexible Environment


I am trying to update a file permission via composer's post-install-cmd but seems to me it is not working correctly though in the log it says the command executed correctly but when I log in to the VM it still show the incorrect permission.

This is what I have in /composer.json

"scripts": {
    "post-root-package-install": [
        "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-install-cmd": [
        "chmod -R 777 public\/external_package\/webmail\/data"
    ]
}

This is what I have in my /app.yaml

runtime: php
env: flex

service: webservice-dev

runtime_config:
  document_root: public
  whitelist_functions: phpversion,phpinfo

env_variables:
  # Environment variables.
  APP_NAME: 'Laravel App (Dev)'
  APP_ENV: dev
  # ...
  # ...

beta_settings:
  cloud_sql_instances: ""

automatic_scaling:
  min_num_instances: 2
  max_num_instances: 10
  cpu_utilization:
    target_utilization: 0.50

resources:
  cpu: 1
  memory_gb: 4

Here is the screenshot of Cloud Build

gcp file permission issue

And this is what I see in VM

dr-xr-x--- 1 root www-data  4096 Jan 28 19:18 data

I want this directory permissions to be 777 rather than 550


Solution

  • This is because App Engine always locks the document root path, for this reason the permissions are reverted.

    Add this to your app.yaml

    runtime_config:
      skip_lockdown_document_root: true
    

    The option skip_lockdown_document_root: true will prevent permissions from being changed.