运行带自动加载的PHP文件时,我收到以下错误:
致命错误:未捕获的异常' UnexpectedValueException'同 消息'流或文件" app.log"无法打开:未能 开放流:权限被拒绝'在 /Users/name/Website2/BuildingWebsiteswithPHP2/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:87 堆栈跟踪:#0 /Users/name/Website2/BuildingWebsiteswithPHP2/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog \ Handler \ StreamHandler-> write(Array)#1 /Users/name/Website2/BuildingWebsiteswithPHP2/vendor/monolog/monolog/src/Monolog/Logger.php(289): Monolog \ Handler \ AbstractProcessingHandler-> handle(Array)#2 /Users/name/Website2/BuildingWebsiteswithPHP2/vendor/monolog/monolog/src/Monolog/Logger.php(341): Monolog \ Logger-> addRecord(300,' Foo',Array)#3 /Users/name/Website2/BuildingWebsiteswithPHP2/index.php(8): Monolog \ Logger-> addWarning(' Foo')#4 {main}引入 的 /Users/name/Website2/BuildingWebsiteswithPHP2/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php 在线 87
这是我的index.php文件:
<?php
require __DIR__ . '/vendor/autoload.php';
$log = new Monolog\Logger('name');
$log->pushHandler(new Monolog\Handler\StreamHandler('app.log', Monolog\Logger::WARNING));
$log->addWarning('Foo');
echo "Hello world!";
我在我的项目文件夹BuldingWebsiteswithPHP2中安装了作曲家。这需要安装在XAMPP吗?
答案 0 :(得分:0)
php进程(通常是Web服务器)没有访问/写入app.log的权限。