'Laravel 5.5 file_put_contents permissions issue

I have a new Laravel project, with Passport and basic authentication installed, and I am getting this error when I try to call the built in /api/register endpoint:

"message": "file_put_contents(/var/www/laravel/storage/framework/cache/data/d6/a4/d6a49710d53593f32f31157f5d15622f91a4bb2b): failed to open stream: No such file or directory",
  "exception": "ErrorException",
  "file": "/var/www/laravel/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php",
  "line": 122,
  "trace": [
    {
      "function": "handleError",
      "class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
      "type": "->"
    },
    {
      "file": "/var/www/laravel/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php",
      "line": 122,
      "function": "file_put_contents"
    },
    {
      "file": "/var/www/laravel/vendor/laravel/framework/src/Illuminate/Cache/FileStore.php",
      "line": 65,
      "function": "put",
      "class": "Illuminate\\Filesystem\\Filesystem",
      "type": "->"
    },
    {
      "file": "/var/www/laravel/vendor/laravel/framework/src/Illuminate/Cache/Repository.php",
      "line": 195,
      "function": "put",
      "class": "Illuminate\\Cache\\FileStore",
      "type": "->"
    },

Note: i replaced the project folder name with "laravel", and this is only the first part of the stack trace, let me know if you guys want the whole thing.

I originally created the project with 5.6, but have since reverted to 5.5 because I thought it was maybe causing this issue. This error is happening while i run the project locally on a virtualbox with ubuntu 16.04 installed, and the web server is nginx. I have already tried using sudo chown -R www-data:www-data /path/to/project/root and sudo chmod -R 775 /path/to/project/root and also sudo chmod -R o+w /path/to/project/root but none of those have worked, and when i use ls -l it still shows that the owner of all the directories is root. I have also tried clearing the caches with php artisan cache:clear and a variety of other cache clearing commands and have also tried just deleting the contents of the cache manually, but i'm still getting the same error. After some attempts to fix this I have also been getting the same error, but referring to framework/views instead of cache.

My theory is that it is trying to write cache files to these locations, but is not able to do so because of permissions issues, so when it tried to go back and access them it is unable to find the files and throws this error, but i could be wrong.

I am able to successfully register a user with the register form, so I am thinking that this has something to do with Passport.

Edit: I have decided to use my own custom endpoint to register the user instead, still using passport to create the authorization token, but I am still getting a similar error that looks like this:

"message": "file_put_contents(/var/www/ink-smart/storage/framework/cache/data/5e/11/5e118760ad926aa34d016256f93a4bc340dcfb75): failed to open stream: Permission denied"

Ive tried using chown and chmod on both the folders inside the virtualbox and in the shared folder on my mac, but nothing is working.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source