Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'The bootstrap/cache directory must be present and writable' error during laravel 6 testing

Laravel 6 includes some additional configuration in phpunit.xml:

<server name="APP_CONFIG_CACHE" value="bootstrap/cache/config.phpunit.php"/>
<server name="APP_SERVICES_CACHE" value="bootstrap/cache/services.phpunit.php"/>
<server name="APP_PACKAGES_CACHE" value="bootstrap/cache/packages.phpunit.php"/>
<server name="APP_ROUTES_CACHE" value="bootstrap/cache/routes.phpunit.php"/>
<server name="APP_EVENTS_CACHE" value="bootstrap/cache/events.phpunit.php"/>

If I run the tests in PHPStorm, I get the following error:

In PackageManifest.php line 168:

The bootstrap/cache directory must be present and writable.

But the bootstrap/cache directory is indeed present and writable. However, if I comment out those new configs in phpunit.xml, my tests run without any errors. How do I fix this?

I also ran php artisan cache:clear. No luck.

like image 465
Tanmay Avatar asked Sep 11 '19 05:09

Tanmay


1 Answers

If you're running Linux, most likely it's a read/write permission problem, to solve these problems, do the following:

Before doing the steps below, be sure to be outside of your Laravel folder

Assuming that your user should be the owner, type the following command:

sudo chown -R user:www-data /path/of/your/laravel/project

Then give the user and webserver permissions as follows:

sudo find /path/of/your/laravel/project -type f -exec chmod 664 {} \;

then run:

sudo find /path/of/your/laravel/project -type d -exec chmod 775 {} \;

After you run those commands, go to your Laravel folder and give the webserver rights to read/write to your bootstrap/cache and storage folder:

sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

It should solve not only your problem but also solves your project security.

like image 68
rkg Avatar answered Sep 19 '22 00:09

rkg