You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

额外疑问

  1. 已在/usr/local/etc/httpd/httpd.conf中修改DocumentRoot为/Users/lamba/Projects/Magento-Open-Source/pub,但执行brew info httpd仍显示默认路径/usr/local/var/www,如何让brew识别修改后的路径?
  2. Homebrew环境中,类似原系统的000-default.conf这类主虚拟主机配置文件在哪里?

内容的提问来源于stack exchange,提问作者Puneet Lamba

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 01:53:11