Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - keep getting log & framework data cache errors

I am using Laravel 6.x inside a Homestead environment and have recently come up with some weird errors when I attempt to login via an Angular frontend - once it hits the login endpoint it gives me some strange errors (see below

The stream or file "/home/vagrant/code/abc-backend/storage/logs/laravel-2020-07-23.log" could not be opened: failed to open stream: Permission denied

The file above doesn't exist for some reason (other log files for other dates exist but not the one from the 23rd July). I have then manually created the file as follows & chmod'd it to 777:

touch storage/logs/laravel-2020-07-23.log
chmod 777 storage/logs/laravel-2020-07-23.log

When I reload the page the previous error has gone but I now get the following error instead :

file_put_contents(/home/vagrant/code/abc-backend/storage/framework/cache/data/1c/6e/1c6ea8378a1030f85a05f4cb2262de1e2164efa6): failed to open stream: No such file or directory",

I have also tried the following with no joy:

chown -R vagrant:www-data /home/vagrant/code/abc-backend/storage

chmod -R g+w /home/vagrant/code/abc-backend/storage

I have tried lots of things with php artisan to try to remedy these errors including running php artisan cache:clear commands with no joy - can anyone else give me an insight into why I am getting both the log file error and the cache/data error & the best methods to fix them both?

Let me know if you need any more info with my setup that will assist.

-- Update -- I am using Virtual Box 6.0 the Homestead box runs Ubuntu 18.04.3 LTS Homestead v10.9.1

Homestead.yaml file --

---
ip: "192.168.10.10"
memory: 2048
cpus: 2
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/Sites
      to: /home/vagrant/code

sites:
    - map: laravel.local
      to: /home/vagrant/code/laravel/public
      type: "laravel"

    - map: abc.local
      to: /home/vagrant/code/abc-ui/app
      type: abc
      variables:
          -   key: abc_TIER
              value: homestead

    - map: dev.abc.local
      to: /home/vagrant/code/abc/public
      type: dev
      variables:
          -   key: abc_TIER
              value: homestead

    - map: api.abc.local
      to: /home/vagrant/code/abc-backend/public

databases:
    - homestead
    - dev

features:
    - mysql8: true
    - pm2: true
    - webdriver: true

variables:
    - key: ABC_TIER
      value: homestead

enter image description here

The framework/data/cache directory looks like this - the subdirectories look the same too (vagrant/vagrant and same drwxrwxrwx permissions).

drwxrwxrwx 1 vagrant vagrant 160 Jul 20 09:50 . drwxrwxrwx 1 vagrant vagrant 160 Jul 17 15:06 .. drwxrwxrwx 1 vagrant vagrant 96 Jul 20 09:50 1c -rwxrwxrwx 1 vagrant vagrant 6148 Apr 3 10:52 .DS_Store -rwxrwxrwx 1 vagrant vagrant 14 Jul 17 15:06 .gitignore

like image 692
Zabs Avatar asked Jul 23 '20 09:07

Zabs


1 Answers

What are you using for web server? nginx or apache?

If you are using nginx, you need to change the group of storage folder as following.

chown -R vagrant:www-data storage

If you are using apache, you need to change the group of storage folder as following.

chown -R vagrant:apache storage

Or please do this.(not recommended)

chmod -R 777 storage
like image 170
NeK Avatar answered Oct 05 '22 22:10

NeK