Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file_put_contents(.../bootstrap/cache/services.json): failed to open stream: No such file or directory

I kept getting this error when running any php artisan commands.

[ErrorException]
file_put_contents(/Applications/MAMP/htdocs/code/bheng/md-bheng/bootstrap/cache/services.json): failed to open stream: No suc
h file or directory

enter image description here

How do I stop that ?

like image 465
code-8 Avatar asked Feb 16 '17 22:02

code-8


1 Answers

Edit - If the services.json file does not exist, run php artisan serve and then stop to forcibly create the file. See: laravel services.json not created

Edit - updated answer to explain each command.

First, ignore the $ at the beginning of each command. These are to indicate that the commands are executed in Terminal.

To find your username, if you don't already know it, run:

$ whoami

For me, this would output rob.

Next we want to change the ownership (chown) of the services.json file. We set the owner to your username (in my case rob) and the group to _www, which is the user MAMP runs as.

$ sudo chown rob:_www /Applications/MAMP/htdocs/code/bheng/md-bheng/bootstrap/cache/services.json

Next we want to change the ownership (chown) of the storage directory. We again set the owner to your username (in my case rob) and the group to _www. You may also notice the -R option. This will execute this command recursively through all of the subdirectories contained within the storage directory.

$ sudo chown -R rob:_www /Applications/MAMP/htdocs/code/bheng/md-bheng/storage

Finally, we want to change the permissions for individual files and directories within the storage directory. The following commands will find within the storage directory, all directories (-type d) or all files (-type f) and execute the command following -exec.

$ sudo find /Applications/MAMP/htdocs/code/bheng/md-bheng/storage -type d -exec chmod 775 {} \;
$ sudo find /Applications/MAMP/htdocs/code/bheng/md-bheng/storage -type f -exec chmod 664 {} \;

The commands we're executing will change mode (chmod) for each directory or file. Read this to learn more about permissions. I've linked to Wikipedia, because it's explains things quite simply. There are likely better resources out there.

Essentially however, 775 will grant read, write and execute permissions on the directories. 664 will grant read and write permissions on the files.

like image 136
fubar Avatar answered Oct 09 '22 21:10

fubar