89

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
  • 893
  • 1
  • 6
  • 4

17 Answers17

230

Try this after you have run the composer update:

php artisan cache:clear
Jim Wright
  • 2,444
  • 1
  • 11
  • 7
  • 1
    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. – Mugoma J. Okomba Jun 30 '17 at 20:33
  • 1
    Not working? i dont have have a cache folder inside bootstrap folder – Shamseer Ahammed Jun 14 '18 at 05:14
  • 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. :) – Grant Jun 01 '21 at 01:25
31

On your Laravel directory file, run:

sudo chmod -R 777 bootstrap/cache/
mpalencia
  • 5,481
  • 4
  • 45
  • 59
  • 7
    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 May 01 '17 at 16:53
  • 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 May 03 '17 at 10:18
  • Must be `sudo chmod -R 777 bootstrap` then only runs fine. – 151291 Dec 03 '18 at 11:09
15

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

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Mohit Poddar
  • 171
  • 1
  • 2
7

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 ~.~ )

Vinay Vissh
  • 457
  • 2
  • 9
  • 12
  • 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. – Vinay Vissh Nov 19 '19 at 10:00
5

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

eaglebearer
  • 2,060
  • 1
  • 13
  • 9
4

Try this too after you have run the composer update:

php artisan config:clear
Waleed Muaz
  • 737
  • 6
  • 17
3

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.

Sadegh Ameri
  • 312
  • 1
  • 8
3
sudo chmod -R ug+rwx storage bootstrap/cache

hopefully, this will solve the problem.

Arif.0o7
  • 61
  • 2
1

it work for me run in project folder

 sudo chmod -R 777 bootstrap/cache

than run

 composer update

than run

 cache:clear
  • 2
    it's not bootstrap/cashe but bootstrap/cache –  Apr 02 '19 at 12:53
  • You shouldn't advice to add chmod 777 to a directory. This is a major security flaw. That way anyone could read, write and execute files in that folder. You can test the security of a given chmod here: https://chmod-calculator.com/ – Francisco Solis Jan 23 '23 at 19:39
1
  • First make sure bootstrap/cache dir is exist if not create a new one mkdir -p bootstrap/cache/
  • Then run php artisan config:cache
Ayman Elshehawy
  • 2,746
  • 23
  • 21
1

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.

cigien
  • 57,834
  • 11
  • 73
  • 112
0

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

0

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

CodeToLife
  • 3,672
  • 2
  • 41
  • 29
0

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: "Please provide a valid cache path" error in laravel

Zellerich
  • 96
  • 2
  • 8
0

In my case, I've found out that the bootstrap/cache is missing in my project during a fresh clone.

Re-adding the cache directory manually solved my issue.

Then running composer install now works fine.

Gams Basallo
  • 1,071
  • 1
  • 11
  • 16
0

OS: Linux Ubuntu

If you are using Docker, maybe try this:

services:
php:
    restart: always
    container_name: app-php
    user: 'www-data:www-data'
volumes:
    - ./:/var/www/html # synchronous

And Open Terminal

sudo chown -R $USER:$USER <your_project>

Now try this:

docker exec -it <your_container_name> /bin/bash
chown -R www-data:www-data bootstrap/
chown -R www-data:www-data storage/

ls -l # You are see folders/files USER/GROUP
php artisan cache:clear # success
php artisan route:clear # success
composer dump-autoload # success
Murat Çakmak
  • 151
  • 2
  • 7
-1

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
Mugoma J. Okomba
  • 3,185
  • 1
  • 26
  • 37