Homebrew版Apache/httpd修改DocumentRoot及相关问题求助
Homebrew Apache 配置问题排查
核心现象
- 使用Homebrew安装的Apache/httpd,已禁用Mac原生版本
- 注释掉
Include /usr/local/etc/httpd/extra/httpd-vhosts.conf时,localhost可正常加载/Users/lamba/www/index.html - 取消上述注释后,Chrome浏览器访问时出现
ERR_CONNECTION_REFUSED错误,Apache日志无有效报错信息
已做权限配置
- 为
/Users/lamba/www及其子目录授予所有用户读权限 - 为
/Users/lamba/Projects及其子目录授予所有用户读、执行权限
关键配置文件内容
httpd.conf
Listen 80 LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so LoadModule php_module /usr/local/opt/php@8.2/lib/httpd/modules/libphp.so DocumentRoot "/Users/lamba/www" <Directory "/Users/lamba/www"> Options Indexes FollowSymLinks AllowOverride all Require all granted </Directory> Include /usr/local/etc/httpd/extra/httpd-vhosts.conf
httpd-vhosts.conf
NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin pslamba@gmail.com DocumentRoot "/Users/lamba/Projects/Magento-Open-Source/pub" ServerName local.m2os.com ErrorLog "/usr/local/var/log/httpd/m2os-error_log" CustomLog "/usr/local/var/log/httpd/m2os-access_log" common <Directory "/Users/lamba/Projects/Magento-Open-Source/pub"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> Header always set Strict-Transport-Security "max-age=0" DirectoryIndex index.php </VirtualHost>
/etc/hosts
## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 127.0.0.1 local.m2os.com 255.255.255.255 broadcasthost ::1 localhost # Added by Docker Desktop # To allow the same kube context to work on the host and the container: 127.0.0.1 kubernetes.docker.internal # End of section 127.0.0.1 ::1 magento.test
后续排查发现
- 即使禁用虚拟主机,localhost指向项目根目录时存在问题:项目根目录的
index.php可被Apache找到,但返回302响应而非执行脚本;未加载PHP模块时,login.php内容被直接显示而非执行(已将index.php添加到DirectoryIndex指令中) - UPDATE:隐藏
index.php后,Apache可正常加载同目录下的index.html,确认问题与PHP相关 - UPDATE 2:在
pub目录创建简单的index.php可正常执行,怀疑问题出在Magento自带的index.php
额外疑问
- 已在
/usr/local/etc/httpd/httpd.conf中修改DocumentRoot为/Users/lamba/Projects/Magento-Open-Source/pub,但执行brew info httpd仍显示默认路径/usr/local/var/www,如何让brew识别修改后的路径? - Homebrew环境中,类似原系统的
000-default.conf这类主虚拟主机配置文件在哪里?
内容的提问来源于stack exchange,提问作者Puneet Lamba
相关产品推荐
相关产品推荐

