php-docs-samples
php-docs-samples copied to clipboard
Can't access files in /tmp on Laravel
I'm setting up Laravel on a Google App Engine standard instance In my config I set
APP_STORAGE: "/tmp"
VIEW_COMPILED_PATH: "/tmp"
But after doing this, Laravel 7 cannot access files in storage/app anymore. I am trying to install https://github.com/spatie/laravel-analytics and this requires a file: app/analytics/service-account-credentials.json
Is it not possible to store a file inside the storage folder and then access it? It does work locally without /tmp
env variables.
The App Engine environment is a read-only filesystem, with the exception of /tmp
. The /tmp
directory is not shared across App Engine instances, so should only be used for caching and other (as implied) temporary storage.
The APP_STORAGE
environment variable is set to /tmp
to prevent Laravel from writing to a read-only filesystem with functions such as the following (taken from Laravel's official documentation):
Storage::disk('local')->put('file.txt', 'Contents');
Permanent resources should be in a different directory. For the laravel-analytics plugin you've mentioned, the credentials can be configured for a different location:
// config/analytics.php
return [
//...
'service_account_credentials_json' => __DIR__ . '/analytics/service-account-credentials.json',
//...
];
If this goes against Laravel conventions, we can recommend something other than setting APP_STORAGE
to /tmp
, but for this case, the above solution seems appropriate.
Looks OK to me. I can put the /analytics/service-account-credentials.json
in a gitignore. Will try it out coming week, thanks!