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

PhpLaravelLaravel 5Composer Php

Php Problem Overview


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'..

Php Solutions


Solution 1 - Php

Try this after you have run the composer update:

php artisan cache:clear

Solution 2 - Php

On your Laravel directory file, run:

sudo chmod -R 777 bootstrap/cache/

Solution 3 - Php

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 - Php

> 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 - Php

Im using cmder on windows 10 in non elevated mode (Non-Admin). command php artisan cache:clear did not work for me. The folder bootstrap/cache did not exist. I created the folder and removed readonly from both bootstrap and bootstrap/cache folder. Both composer install and composer update are working now.

Solution 6 - Php

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

Solution 7 - Php

sudo chmod -R ug+rwx storage bootstrap/cache

hopefully, this will solve the problem.

Solution 8 - Php

Try this too after you have run the composer update:

php artisan config:clear

Solution 9 - Php

it work for me run in project folder

 sudo chmod -R 777 bootstrap/cache

than run

 composer update

than run

 cache:clear

Solution 10 - Php

  • First make sure bootstrap/cache dir is exist if not create a new one mkdir -p bootstrap/cache/
  • Then run php artisan config:cache

Solution 11 - Php

Simple. There are applications that can block the directory. Like google drive synchronizer, One driver synchronizer, or any other application that is using windows explorer.

Delete cache folder. Create this again.

Solution 12 - Php

Try executing the following commands in your project root directory

composer update

then do

composer dumpautoload

this will avoid the necessity of messing with cache files which may lead to whole new sort of issues

Solution 13 - Php

I don't imagine what I got done wrong with that before and no games around with that cashclearings had sense. But as it claims there was no 'cache' folder inside /bootstrapp . Had to have create it manually. Now it all rocks ok again

Solution 14 - Php

I had to create these five folders to be able to run artisan again.

mkdir bootstrap/cache
mkdir storage/framework
mkdir storage/framework/cache
mkdir storage/framework/views
mkdir storage/framework/sessions

Answer was found in this related question: https://stackoverflow.com/questions/38483837/please-provide-a-valid-cache-path-error-in-laravel

Solution 15 - Php

If a web server (e.g. Apache or Nginx) is being used as a front-end the solution is to make the directory bootstrap/cache owned by web server group. For Nginx:

 $ sudo chgrp -R nginx bootstrap/cache
        

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPeter BenninkView Question on Stackoverflow
Solution 1 - PhpJim WrightView Answer on Stackoverflow
Solution 2 - PhpmpalenciaView Answer on Stackoverflow
Solution 3 - PhpMohit PoddarView Answer on Stackoverflow
Solution 4 - PhpVinay VisshView Answer on Stackoverflow
Solution 5 - PhpSadegh AmeriView Answer on Stackoverflow
Solution 6 - PhpeaglebearerView Answer on Stackoverflow
Solution 7 - PhpArif.0o7View Answer on Stackoverflow
Solution 8 - PhpWaleed MuazView Answer on Stackoverflow
Solution 9 - Phpmohamed elshazlyView Answer on Stackoverflow
Solution 10 - PhpAyman ElshehawyView Answer on Stackoverflow
Solution 11 - PhpLesnier GonzalezView Answer on Stackoverflow
Solution 12 - PhpSoftware DeveloperView Answer on Stackoverflow
Solution 13 - PhpCodeToLifeView Answer on Stackoverflow
Solution 14 - PhpZellerichView Answer on Stackoverflow
Solution 15 - PhpMugoma J. OkombaView Answer on Stackoverflow