Report this

What is the reason for this report?

App platform store Laravel Passport keys as variable

Posted on April 29, 2021

I have deployed Laravel app with passport authentication on DigitalOcean App Platform. The problem occur when the app gets deployed again and I need to generate new passport keys (php artisan passport:install). Is there a way to store those two files (oaut-private.key and oauth-public.key) as environment variables? I am new to this and I don’t really know how it works… Thanks for help!



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

👋🏼 @brackog

Please let me know if I misunderstood your question, but I believe you can achieve this like so:

First, store the files’ contents in env vars and make sure to check the “Encrypt” box

  1. Key: PASSPORT_OAUTH_PRIVATE_KEY Value: contents of oauth-private.key
  2. Key: PASSPORT_OAUTH_PUBLIC_KEY Value: contents of oauth-public.key

Then, update your app’s run command to first write the files using the content from the env vars and then start Laravel:

echo -n "$PASSPORT_OAUTH_PRIVATE_KEY" >storage/oauth-private.key
echo -n "$PASSPORT_OAUTH_PUBLIC_KEY" >storage/oauth-public.key

heroku-php-apache2 public/

The -n flag stops echo from adding a newline at the end of the file in case that affects Laravel Passport.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.