当运行带有自动加载的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->写入(数组)#1/Users/name/Website2/BuildingWebsiteswithPHP2/vendor/monolog/monolog/src/monolog/Loger.php(289):Monolog\Handler\AbstractProcessingHandler->句柄(数组)#2/Users/name/Website2/BuildingWebsiteswithPHP2/vendor/monolog/monolog/src/monolog/Loger.php(341):Monolog\Logger->addRecord(300,"Foo",数组)#3/用户/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 MonologLogger('name');
$log->pushHandler(new MonologHandlerStreamHandler('app.log', MonologLogger::WARNING));
$log->addWarning('Foo');
echo "Hello world!";
我在我的项目文件夹BuldingWebsiteswithPHP2中安装了composer。是否需要将其安装在XAMPP中?
php进程(通常是web服务器)没有访问/写入app.log的权限。