没有这样的文件或目录:AH02291:无法访问主错误日志的目录“/usr/logs/”AH00014:配置检查失败

No such file or directory: AH02291: Cannot access directory '/usr/logs/' for main error log AH00014: Configuration check failed

我正在尝试在我的 MacOS Sierra 上安装和配置 PHP 7.2。安装后,我无法启动 Apache 服务器并出现以下错误。

No such file or directory: AH02291: Cannot access directory '/usr/logs/' for main error log
AH00014: Configuration check failed

我也尝试创建“/usr/logs/”目录,但这是不允许的。 我正在使用的命令:

$sudo apachectl start
$apachectl configtest

有什么帮助吗?

Apache 需要对日志的写入权限:

On osx /usr 是一个受保护的目录,系统不允许在其中手动创建子目录。

  • 创建目录/logs sudo mkdir /logs
  • 设置权限sudo chmod 775 /logs
  • 设置所有者sudo chown {your-apache-user}:{your-apache-group} /logs
  • 可选地,您可以将 apache 用户添加到当前目录所有者的组中(这将是一个更通用和更清洁的解决方案),而不是让 apache 成为所有者
  • 在 apache 配置中(不要忘记虚拟主机),将日志目录更改为 新目录
  • 重启apache

更好的选择:使用 Vagrant https://www.vagrantup.com/ ,这样你就不会浪费你的 OS

https://support.plesk.com/hc/en-us/articles/214527565-Unable-to-start-Apache-when-Apache-logs-directory-is-missing-No-such-file-or-directory-Unable-to-open-logs也给出了一个完整和令人满意的解决方案:

如果报错信息是

Starting httpd: (2)No such file or directory: httpd: could not open error log file /etc/httpd/logs/error_log.
Unable to open logs

httpd[26817]: AH00526: Syntax error on line 43 of /etc/httpd/conf.d/mod_security.conf: httpd[26817]: ModSecurity: Failed to open debug log file: /var/log/httpd/modsec_debug.log

[error] (2)No such file or directory: mod_jk: could not open JkLog file /var/log/httpd/mod_jk.log Configuration Failed

甚至

apachectl[1891]: (2)No such file or directory: AH02291: Cannot access directory '/var/log/apache2/' for main error log
apachectl[1891]: (2)No such file or directory: AH02291: Cannot access directory '/var/log/apache2/' for error log of vhost defined at /etc/apache2/sites-enabled/000-default.conf:1

然后 运行(作为 root):

mkdir /var/log/httpd
chmod 700 /var/log/httpd/
service httpd start

mkdir /var/log/apache2
chmod 750 /var/log/apache2
chown root:adm /var/log/apache2
 service apache2 start

应该做!