【问题标题】:file_put_contents failed to open stream: No such file or directory , Installfile_put_contents 未能打开流:没有这样的文件或目录,安装
【发布时间】:2019-06-03 01:41:00
【问题描述】:

我从 bitbuket 克隆了一个 laravel 项目。还运行所有必要的命令来获取所有供应商文件,例如:

composer dump-autoload
composer install
php artisan cache:clear
php artisan clear-compiled

还删除了文件/public_html/bootstrap/cache/config.php

但是当我尝试启动项目时出现以下错误:

file_put_contents(C:\xampp\htdocs\laravelstart\storage\framework/sessions/sRPb1A6BKrshhH8HPAR2fXVEcCH4daYCLxgo4b8M): 无法打开流:没有这样的文件或目录

【问题讨论】:

标签: php laravel


【解决方案1】:

试试这个命令:php artisan config:cache 它会清除你项目的配置缓存。问题可能是你克隆了它,并且没有为你的新服务器准备好配置:)

【讨论】:

  • 我做了,但问题没有解决
【解决方案2】:

rm -rf bootstrap/cache/config.php(删除)

php 工匠配置:缓存

【讨论】:

  • 我做了,但问题没有解决
  • 尝试 php artisan config:clear php artisan cache:clear php artisan config:cache
【解决方案3】:

如果清理缓存不起作用(例如,当您在 docker 下运行时可能会发生这种情况),请再次尝试 chmod 755 storage bootstrap/cache。它对我有用

【讨论】:

    【解决方案4】:

    cd 到您的/storage/framework/cache/data/storage/framework/sessionsframework 文件夹中的任何目录,然后输入ls -la,您可能会看到如下内容:

    drwxr-sr-x  3 apache   apache   16 Oct 16 13:00 bd
    drwxr-sr-x  3 apache   apache   16 Oct 16 17:38 be
    drwxr-sr-x  3 root     apache   16 Oct 17 05:00 bf
    drwxr-sr-x  3 apache   apache   16 Oct 16 13:07 c6
    drwxr-sr-x  3 root     apache   16 Oct 16 16:15 d3
    drwxr-sr-x  3 apache   apache   16 Oct 17 12:32 dd
    drwxr-sr-x  3 apache   apache   16 Oct 17 12:32 e2
    drwxr-sr-x  3 root     apache   16 Oct 16 16:00 e9
    drwxr-sr-x  3 apache   apache   16 Oct 16 21:25 f6
    drwxr-sr-x  3 apache   apache   16 Oct 16 16:56 f8
    drwxr-sr-x  4 apache   apache   26 Oct 17 06:00 fa
    

    如您所见,一些目录归root 所有,将这个cd 修复到storage 目录并运行:

    (首先检查您需要哪个user:group,对于AWS,它可能是ec2-user:apache):

    sudo chmod 2775 . && sudo chown -R apache:apache . && sudo chmod -R og-r . && sudo find . -type d -exec chmod g=rwxs "{}" \; && sudo find . -type f -exec chmod g=rw  "{}" \; && sudo setfacl -d -m g::rwx . && sudo setfacl -d -m o::rx .
    

    每次从存储库推送更改时,您可能希望将其包含在部署脚本中。

    【讨论】:

      【解决方案5】:

      进入目录laravel/bootstrap/cache并删除co​​nfig.php文件。

      【讨论】:

        【解决方案6】:

        你也可以试试这个,它对我有用php artisan optimize:clear

        【讨论】:

          【解决方案7】:

          我遇到了类似的问题,我的问题是文件名太长,您将文件命名为:C:\xampp\htdocs\laravelstart\storage\framework/sessions/sRPb1A6BKrshhH8HPAR2fXVEcCH4daYCLxgo4b8M

          我建议: 尝试使用较短的名称。或者尝试将文件保存在没有路径的根目录中。或者检查您是否在路径中使用了正确的斜杠或使用了较短的路径,在我的情况下,我使用了这个:file_put_contents('./storage/pdfs/file.jpg');

          【讨论】:

          • 尝试使用较短的文件名?是的!做到了!谁知道 Windows 会将这些缺陷带到他们的服务器环境中!
          猜你喜欢
          • 2013-01-24
          • 2018-12-01
          • 2014-09-05
          • 2015-11-14
          • 2017-07-06
          • 1970-01-01
          • 2020-01-12
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多