Alex Brend
Alex Brend

Reputation: 61

"The stream or file "/srv/storage/logs/laravel-2019-01-09.log" could not be opened: failed to open stream: Read-only file system"

We are trying to connect with laravel and app engine but we are facing issue of storage permission. Is there any way to change storage path to app engine storage path. So we could solve permission denied issue.

As app engine does not have read and write permission.

Here i have attached my app yaml file details

runtime: php72

runtime_config:

document_root: public

env_variables:

  #Put production environment variables here.
  #LOG_CHANNEL: stackdriver
  APP_NAME: eProfit
  #APP_ENV: local
  #APP_DEBUG : true # or false 
  APP_LOG: errorlog
  APP_KEY: base64:3KcvHI2FZIT5n0BeiXynkjfvI9O7AzdOpeYhD4W4WgQ=
  #STORAGE_DIR: /tmp
  #APP_STORAGE : /tmp
  CACHE_DRIVER: file
  SESSION_DRIVER: file

## Set these environment variables according to your CloudSQL configuration.

  DB_HOST: localhost
  DB_DATABASE: databasename
  DB_USERNAME: root
  DB_PASSWORD: password
  DB_SOCKET: DB_SOCKEt

beta_settings:

cloud_sql_instances: "eprofit-3:us-central1:eprofit-3"

Upvotes: 1

Views: 7927

Answers (5)

Mondy
Mondy

Reputation: 2295

Did you solved this Google App Engine problem? I think you can't set the permissions to the app engine, because it is all write protected.

Upvotes: 0

jave.web
jave.web

Reputation: 15072

TL;DR - purposely different storage location => GOTO Case 2

Case 1: You want storage/logs to be placed in /srv/...

Laravel storage directory is commonly placed in the app root - typically something like /var/www/projectname/storage
However you of course could decide, you want the storage (and logs) to send purposely elsewhere (in your case /srv/storage / /srv/storage/logs
=> if this is unwanted/by accident or you wish to store it elsewhere - see Case2

Regardless of where you have your storage - system user that runs the app (typically webserver like apache) should have permissions to write to the storage directory and files - how to do that is a different question, already answered here - How to set up file permissions for Laravel?.
Basically you make sure the system-user running the app (e.g. www-data) has read&write permissions of the storage directory and files as an owner or as a group (where system-user and owner are in) (maximum 775).

NEVER GIVE 777 PERMISSIONS (SECURITY ISSUES)

Case 2: Purposedly change storage/logs location

In some cases you want to place storage/logs elsewhere, that is quite easily doable in bootstrap/app.php with this code:

$app->useStoragePath("/ABSOLUTE/PATH/TO/STORAGE/NOTRAILINGSLASH")

I however don't recommend doing this with plain string - you should use .env file(s) to define storage path in each environment and here dynamically get it if available with
env('YOUR_STORAGE_PATH_ENV_VARIABLE)

So you end up with something like this in bootstrap/app.php file:

$envStoragePath = env('YOUR_STORAGE_PATH_ENV_VARIABLE');
if (!empty($envStoragePath)) {
   $app->useStoragePath($envStoragePath);
}
// condition can be shorten to:
// empty($envStoragePath)) ?: $app->useStoragePath($envStoragePath);

And with something like this in .env file(s):

YOUR_STORAGE_PATH_ENV_VARIABLE = '/YOUR/ENVIRONMENT/SPECIFIC/STORAGE/PATH'

Upvotes: 1

user10186369
user10186369

Reputation:

Please run below command

sudo chmod -R 777 /srv/storage/

Upvotes: 0

Jignesh Joisar
Jignesh Joisar

Reputation: 15175

run this command in terminal used chmod

sudo chmod -R 0777 /srv/storage/logs/

Upvotes: 0

Murad Asgarov
Murad Asgarov

Reputation: 108

give permission to /storage folder.

chmod 777 -R /storage

Upvotes: 0

Related Questions