Search code examples
phpgoogle-app-enginehandlerapp.yaml

Error 404 ngix - GAE php - How to properly define subfolders in the handlers attributes of app.yaml file?


i have some problems with the app.yaml file definition. I have tried to deploy a simple application on GAE, but i always get a 404 error everytime i try to access my app at https://myapp.appspot.com/api/v1/validate:

Here the folder structure:

  • app.yaml
  • web
    • api
      • v1
        • validate
          • index.php

Here my app.yaml code:

  runtime: php
  env: flex

  runtime_config:
   document_root: web

  handlers:
  - url: /api/v1/validate/.*
    script: index.php

what did I do wrong? Thank you in advance


Solution

  • I managed to successfully deploy a similar setup. Here are my changes:

    Access URL: https://YourProject.appspot.com/api/v1/validate/index.php

    In index.php modified line 20 as require_once __DIR__ . '/../../../../vendor/autoload.php';

    In app.yaml added handler as:

    runtime: php
    env: flex
    
    runtime_config:
     document_root: web
    
    handlers:
    - url: /api/v1/authenticate
      script: /api/v1/authenticate/index.html
    
    - url: /api/v1/userprofile
      script: /api/v1/userprofile/index.php
    

    And its working just fine.

    For this, I just followed the Quickstart for PHP in the App Engine Flexible Documentation and modified the helloworld directory as

    My folder structure its the exact same as you.

    Update

    After taking a look at your code I managed to deploy an app like with these settings

    app.yaml

    runtime: php
    env: flex
    
    runtime_config:
     document_root: web
    
    handlers:
    - url: /api/v1/authenticate
      script: /api/v1/authenticate/index.html
    
    - url: /api/v1/userprofile
      script: /api/v1/userprofile/index.php
    

    index.php

    <?php
    
        include '../../utils.php';
        require_once __DIR__ . '/../../../../vendor/autoload.php';
        $app = new Silex\Application();
        $app->get('/', function () {
        return 'Hello World';
        });
        $app->get('/goodbye', function () {
        return 'Goodbye World';
        });
        // @codeCoverageIgnoreStart
        if (PHP_SAPI != 'cli') {
        $app->run();
        }
        // @codeCoverageIgnoreEnd
        return $app;
    ?>
    

    What I see is that you aren't handling the http request in a proper way. You can take a look at the index.php added above, if you replace one of your index.php codes with this code you will see that the yaml file will let you connect to your app at https://YOUR_APP.devshell.appspot.com/api/v1/userprofile/index.php