laravel file_put_contents(.../bootstrap/cache/services.json):无法打开流:没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42286218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
file_put_contents(.../bootstrap/cache/services.json): failed to open stream: No such file or directory
提问by cyber8200
I kept getting this error when running any php artisan
commands.
运行任何php artisan
命令时,我不断收到此错误。
[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
[ErrorException]
file_put_contents(/Applications/MAMP/htdocs/code/bheng/md-bheng/bootstrap/cache/services.json):无法打开流:没有这样的
文件或目录
How do I stop that ?
我该如何阻止?
采纳答案by fubar
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
编辑- 如果services.json
文件不存在,则运行php artisan serve
然后停止以强制创建文件。请参阅:未创建 laravel services.json
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
.
对我来说,这将输出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.
接下来我们要CH昂热的自己ership(chown
中的)services.json
文件。我们将所有者设置为您的用户名(在我的情况下rob
),将组设置为_www
,即 MAMP 运行的用户身份。
$ 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.
接下来我们要CH昂热的自己ership(chown
中)的storage
目录。我们再次将所有者设置为您的用户名(在我的情况下rob
),并将组设置为_www
。您可能还会注意到该-R
选项。这将通过目录中包含的所有子目录递归执行此命令storage
。
$ 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
.
最后,我们要更改存储目录中各个文件和目录的权限。以下命令将find
在storage
目录、所有目录 ( -type d
) 或所有文件 ( -type f
) 中执行以下命令-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.
我们要执行的命令将CH昂热MODE( chmod
)为每个目录或文件。阅读本文以了解有关权限的更多信息。我已经链接到维基百科,因为它很简单地解释了事情。那里可能有更好的资源。
Essentially however, 775
will grant read, write and execute permissions on the directories. 664
will grant read and write permissions on the files.
然而,本质上,775
将授予对目录的读取、写入和执行权限。664
将授予对文件的读写权限。
回答by Manjunath Reddy
[ErrorException]
file_put_contents(/var/www/project/bootstrap/cache/services.php):
failed to open stream: No such file or directory
For me, it was because of boostrap/cache
folder.
I deleted the cache
forcefully, hence I hit this error.
对我来说,这是因为boostrap/cache
文件夹。我cache
强行删除了,因此我遇到了这个错误。
Just create back the cache
folder, it would work fine.
只需创建回cache
文件夹,它就可以正常工作。
$>cd projectDir/boostrap
$>cd projectDir/boostrap
$>projectDir/boostrap
> mkdir cache
$>projectDir/boostrap
> mkdir 缓存
would work
会工作