Table of Contents

背景

本次PHP开发环境搭建基于MacOS(13.1)、PhpStorm(2020.3)和Apache2(Apache/2.4.57)进行搭建,PHP选定版本为8.0。其中Apache2和PHP通过Homebrew进行安装,具体可以参考下面的文章。

MacOS踩坑记之Library not loaded: libunistring.2.dylib|libtiff.5.dylib

环境搭建完毕后编写一个index.php:

<?php phpinfo()?>

放入httpd.conf中指定的根目录后通过浏览器打开居然无法访问:

问题排查

首先排查PHP,首先停止Apache2然后通过命令行启动PHP内置Server:

sudo php -S localhost:80
[Sun Oct  8 09:51:41 2023] PHP 8.0.30 Development Server (http://localhost:80) started

打开localhost发现页面非常正常,那应该是Apache2设置的问题了。

重新启动Apache2通过查看error日志发现问题:

[Sun Oct 08 08:06:39.213096 2023] [core:crit] [pid 5491] (13)Permission denied: [client ::1:49588] AH00529: /Users/uexf/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/Users/uexf/' is executable
[Sun Oct 08 08:06:40.176660 2023] [core:crit] [pid 5491] (13)Permission denied: [client ::1:49588] AH00529: /Users/uexf/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/Users/uexf/' is executable
[Sun Oct 08 08:06:40.361256 2023] [core:crit] [pid 5491] (13)Permission denied: [client ::1:49588] AH00529: /Users/uexf/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/Users/uexf/' is executable
[Sun Oct 08 08:06:40.510741 2023] [core:crit] [pid 5491] (13)Permission denied: [client ::1:49588] AH00529: /Users/uexf/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/Users/uexf/' is executable
[Sun Oct 08 08:06:40.679030 2023] [core:crit] [pid 5491] (13)Permission denied: [client ::1:49588] AH00529: /Users/uexf/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/Users/uexf/' is executable
[Sun Oct 08 08:06:47.432642 2023] [core:crit] [pid 5492] (13)Permission denied: [client ::1:49589] AH00529: /Users/uexf/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/Users/uexf/' is executable

在网上翻资料找到官方的一段解释:

1.Just ask httpd to stop looking for .htaccess files by setting AllowOverride None in httpd.conf for the relevant directories.
2.Fix the file-system permissions on the directory path (often /home/user). chmod 755 is usually sufficient, and you can set stricter permissions if httpd is configured to run under the user or group that owns the directory.

通读了一下后突然意识到问题问题所在,那就来复盘一下:

隐藏内容
本内容需评论后查看
声明
1.本网站名称: 优易先锋资源网
2.本站永久网址:https://res.uexf.com
3.本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长support@uexf.com
4.本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责
5.本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6.本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新