Laravel throws 'The bootstrap/cache directory must be present and writable' error after update

111,276

Solution 1

Try this after you have run the composer update:

php artisan cache:clear

Solution 2

On your Laravel directory file, run:

sudo chmod -R 777 bootstrap/cache/

Solution 3

The best way to resolve this error is : 1. Open your project folder 2. Move to the bootstrap directory 3. Create an empty folder named as "cache" 4. Then do php artisan cache: clear This will work for sure

Solution 4

Short version: If uploading using something like AWS eb cli Verify if bootstrap/cache folder (not talking about its contents) is being deployed.


Some background behind my answer

I am using Amazon Web Services' Elastic Beanstalk to host my Laravel project. As I just started using Laravel I do not have much idea about its functioning. Two days back My new deployments were all crashing midway with OP's error message.

Earlier that day, I realised that I was not using

 php artisan config:cache

to cache configurations to make things faster. And I added the same in composer.json's "post-install-cmd" and "post-update-cmd" clauses.
And I also added statement in .ebignore file to not upload the content of /bootstrap/cache (as its content is environment dependent a.k.a my localhost configurations have no meaning on my production server)

And facepalm I did not realise that this will stop the bootstrap/cache folder from being uploaded (as Like git, eb cli ignores empty folders).
So, when I started to deploy at night The deployments were meant to crash.

So, now I have just placed empty-placeholder (say) .gitkeep file in bootstrap/cache. And deployments are working once again :)
(Though the problem was so simple I realised the reason after ssh-ing and digging an EBS EC2 instance for some sweet sleep hours ~.~ )

Solution 5

For me, I manually created the cache folder inside bootstrap.

Share:
111,276
Peter Bennink
Author by

Peter Bennink

Updated on July 05, 2022

Comments

  • Peter Bennink
    Peter Bennink almost 2 years

    I used 'composer update', which updated a few packages. During the updating process the website still functions. However, after it says 'The compiled services file has been removed', the website doesn't load and instead says:

    Exception in ProviderRepository.php line 190:
    The bootstrap/cache directory must be present and writable.
    

    The weirdest thing is, when I run 'composer update' again, the website starts to work again, until the compiled services file is removed, at which point it throws the same error again. I have already tried the usual things that should be done when this error appears (chown -R everything to the right user/group and chmod all the files and folders 664 and 775 respectively).

    I don't know what to do anymore, as the error doesn't seem 'correct'..

  • Peter Bennink
    Peter Bennink about 7 years
    I'm pretty sure 777'ing any folder on a web server isn't such a good idea security-wise. Besides, 775 should and has worked.
  • Peter Bennink
    Peter Bennink almost 7 years
    I'm sorry, I wasn't clear. 775 has worked in the past. At the moment I still have the same problem, as I stated in the original post, I already tried 775'ing and 664'ing everything. The problem is exactly that: I fix what the error says should be fixed, but I still get the same problem.
  • Peter Bennink
    Peter Bennink almost 7 years
    Waaaay too late, but this was the simple solution. I forgot to let you know, but thank you!
  • Mugoma J. Okomba
    Mugoma J. Okomba almost 7 years
    A warning is appropriate here. Before running this on production stop and ask yourself if you really want top wipe out your cache. Otherwise, you might end up crippling your app like it happened to me.
  • Shamseer Ahammed
    Shamseer Ahammed almost 6 years
    Not working? i dont have have a cache folder inside bootstrap folder
  • 151291
    151291 over 5 years
    Must be sudo chmod -R 777 bootstrap then only runs fine.
  • Admin
    Admin about 5 years
    it's not bootstrap/cashe but bootstrap/cache
  • Vinay Vissh
    Vinay Vissh over 4 years
    It would be very kind of you if you can tell me why you downvoted my answer. Because as much as I can see, it solves a specific occurrence of the asked problem.
  • Wal Heredia
    Wal Heredia about 4 years
    you actually saved my life!
  • Grant
    Grant almost 3 years
    Also, if this solution doesn't work straight away - check if you have something like OPCache running you may have to restart your PHP-FPM / clear your OPCache cache. :)
  • Giangimgs
    Giangimgs almost 2 years
    Me too, just delete the current cache folder and recreate it, then problem will be fixed