2

I have installed fresh laravel 5.6 but when i open laravel public... its give me error as per below

/var/lib/jenkins/workspace/ytl/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php

$this->createDir();
        $this->errorMessage = null;
        set_error_handler(array($this, 'customErrorHandler'));
        $this->stream = fopen($this->url, 'a');
        if ($this->filePermission !== null) {
            @chmod($this->url, $this->filePermission);
        }
        restore_error_handler();
        if (!is_resource($this->stream)) {
            $this->stream = null;
            throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$this->errorMessage, $this->url));
        }
    }

    if ($this->useLocking) {
        // ignoring errors here, there's not much we can do about them
        flock($this->stream, LOCK_EX);
    }

    $this->streamWrite($this->stream, $record);

    if ($this->useLocking) {
        flock($this->stream, LOCK_UN);
    }
}

"The stream or file "/var/lib/jenkins/workspace/ytl/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied"

  • Likely another error happening but the web user doesn't have access to write to your logs. Pretty clear error message, did you check the privileges of your web user on storage/logs? – Devon Bessemer Jun 21 '18 at 23:34
  • Yes @Devon another view has same error... I given both folders 777 permissions then site opened –  Jun 21 '18 at 23:49

1 Answers1

2

You need to run chmod 775 -R storage at the root directory of your project. This will allow the user running PHP to write to that directory. You may also need to do this with the bootstrap directory.

Nick
  • 2,593
  • 3
  • 30
  • 59
  • 1
    Those are pretty wide open privileges for the entire storage directory. I wouldn't recommend that on a shared server... It also still wouldn't be writeable if the web user isn't the owner or belonging to a group. – Devon Bessemer Jun 21 '18 at 23:41
  • Agreed, however, it is required for some infrastructure providers such as Google App Engine and AWS Beanstalk. Otherwise its a matter of changing the owner of the entire directory – Nick Jun 21 '18 at 23:43
  • It's worked but, is it not good for project? @Nick –  Jun 21 '18 at 23:48
  • @KinnariPrajapati as Devon describes, if you are on a shared server (other people also hosting on the same server) then you would be best changing the user/owner of the folder. Are you running on a shared server? – Nick Jun 21 '18 at 23:59
  • 1
    I have my own sever @Devon –  Jun 22 '18 at 00:00
  • 1
    Then 775 should be fine as you don't have to worry about others having execute/read permissions to the files in those directories. – Devon Bessemer Jun 22 '18 at 00:04
  • This answer is good, and you can also check this one if you're still getting error: [https://stackoverflow.com/questions/23411520/how-to-fix-error-laravel-log-could-not-be-opened](https://stackoverflow.com/questions/23411520/how-to-fix-error-laravel-log-could-not-be-opened) – nekiala Sep 19 '18 at 21:43