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

2

7

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.

Peag answered 11/9, 2019 at 5:28 Comment(2)
Possible duplicate of How to set up file permissions for Laravel?Benefactor
@Benefactor No. See my answer.Peag
P
1

This was an issue from Laravel end:

https://github.com/laravel/framework/issues/29862

This PR Fixes that issue.

Updating the framework version to the latest version (6.0.3 as of the time of this answer) fixes the problem.

Peag answered 12/9, 2019 at 10:57 Comment(0)
B
7

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.

Basanite answered 11/9, 2019 at 5:50 Comment(1)
This is an answer you want to read. Simple and straight forward.Aptitude
P
1

This was an issue from Laravel end:

https://github.com/laravel/framework/issues/29862

This PR Fixes that issue.

Updating the framework version to the latest version (6.0.3 as of the time of this answer) fixes the problem.

Peag answered 12/9, 2019 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.