skip to Main Content

I have a Laravel 8 application, running on a Cent OS 8.4 VM. I’m using the jwt-auth package by Tymondesigns to implement auth on my project, it’s being used an an API.

When I set up the project on the server, and deploy it, the storage folder in Laravel is moved to the shared directory as part of the deployer project, and for some reason, despite setting permissions of the storage folder, I’m seeing that not every folder, in particular the ee cache folder has the wrong permissions, and I’m getting a permission denied error thrown by the JWT auth package:

file_put_contents(/var/www/project-beacon-api/releases/37/storage/framework/cache/data/ee/67/ee673b1cd21b0cd9eca15c240d66269df17f9b3a): failed to open stream: No such file or directory

I can’t understand why I’m getting this error, and for as long as I’ve worked with Laravel, setting permissions of the storage folder to 755 / 775 has never worked, and trying to open the website always throws a permission denied.

What am I missing in the permissions configuration, what do I need to run to solve this once and for all?

permissions

It always seems to be the ee folder!

2

Answers


  1. The error is happening because of the laravel cache
    Before running this command
    Go to .env file in you project you will find

    CACHE_DRIVER = file
    

    then change the cache driver to this

    CACHE_DRIVER = array
    

    When it comes to using cache in Laravel you have 3 possible "families" that you should consider:

    Temporary/Debug

    array

    Always available

    file
    database
    APC (I would not trust this one since PHP7)

    Dedicated

    Redis

    Memcached

    Since you can easily replace the cache drivers you don’t need to pick one based on your use case, but more based on your server needs/load and possibilities.

    For example on your development machine, I suggest using a file, since this way you won’t need any extra software clogging your PC plus you gain the ability to quickly clear the cache even if you do something really bad like breaking the artisan command. All you need to do is delete the storage/framework folder and you have a fresh instance again (make sure to regenerate the .gitignore files from your repository after that)

    For your main server, you have to think about your possibilities. If you have one of those free hosting websites you almost certainly won’t be able to install any new software, so you can consider using a file or database. Even though the database will probably be faster than a file, it is in most cases the weakest point of your website, and trying to push even more data into that bottleneck is not a good idea, that is why I would suggest against using it, and instead stick to files.

    If you have a dedicated server then you should definitely pick Memcached or Redis. Which one of the two? It depends on many factors, and you can find a lot of comparisons online, just look for one. I personally prefer Redis because of its ability to persist data, but either one is a good solution

    Login or Signup to reply.
  2. You need to have ownership for your entire project (user:group) [use ls -la to see ownership in your project root folder]

    If not right, use chown:
    sudo chown -R yourUserName:www-data /path/to/project

    If ownership’s ok, just set permissions for storage folder like that: sudo chmod -R 775 storage/ so you can have the right to write

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search