Search code examples
sqllaravelgoogle-app-enginegoogle-cloud-platformlaravel-passport

Trouble deploying Laravel Passport with Google App Engine (GAE)


I have successfully deployed and maintained a Google App Engine + Laravel Project using Google Cloud SQL as a database. I'm using Cloud Build to deploy, however on manual deployment my problem occurs just the same. I'm trying to get the locally working Laravel Passport installation to work on Google App Engine.

Laravel Passport needs to run php artisan passport:install in order to generate it's encryption keys and stow them into the database.
The only slot where this is possible in the GAE automatic build process is in "post-install-cmd":[] in composer, however at that stage the database connection is not established yet. => SQL Error while running passport:install


However

I have also tried SSHing into the App Engine Instance and running passport:install manually, chmod'ing the storage directory to 0600, chown'ing the required passport encryption keys to www-data and yet I still get the following error:
LogicException Key path "file:///app/storage/oauth-private.key" does not exist or is not readable

I am at a lack of options now and sadly cannot find a reference where Laravel Passport has been deployed to a GAE Project.

What I'm looking for is another viewpoint of what might be going wrong. Am I missing something with permissions that's specific to Google App Engine?

Thanks in advance!


Solution

  • i got the same issue and this solution worked for me. please translate in english as the content on this site is in chinese.

    Put passport settings in environment variables

    Creating a configuration file.

    php artisan vendor:publish --tag=passport-config
    

    Embed file contents in environment variables

    php artisan passport:install 
    

    The following files are created in

    storage/oauth-private.key

    storage/oauth-private.key

    Put the contents of this key file in the configuration file as follows

    //app.yaml
    runtime: php72
    
    env_variables:
      APP_KEY: YOUR_APP_KEY
      APP_STORAGE: /tmp
      VIEW_COMPILED_PATH: /tmp
      CACHE_DRIVER: database
      SESSION_DRIVER: database
      ## Set these environment variables according to your CloudSQL configuration.
      DB_DATABASE: YOUR_DB_DATABASE
      DB_USERNAME: YOUR_DB_USERNAME
      DB_PASSWORD: YOUR_DB_PASSWORD
      DB_SOCKET: "/cloudsql/YOUR_CONNECTION_NAME"
    +   PASSPORT_PRIVATE_KEY: |
    +     -----BEGIN RSA PRIVATE KEY-----
    +     <private key here>
    +     -----END RSA PRIVATE KEY-----
    +   PASSPORT_PUBLIC_KEY: |
    +     -----BEGIN PUBLIC KEY-----
    +     <public key here>
    +     -----END PUBLIC KEY-----