# 启动 Apache 并设置开机自启
brew services start httpd
# 停止服务
brew services stop httpd
# 重启服务
brew services restart httpd
# 查看服务状态
brew services list | grep httpd
LoadModule php_module /opt/homebrew/opt/php@8.1/lib/httpd/modules/libphp.so
# 安装 PHP 8.1(指定版本)
brew install php@8.1
# 链接 PHP 到系统路径(确保全局可用)
brew link php@8.1 --force --overwrite
# 验证安装是否成功
php -v
在 <IfModule mime_module> 块内添加:
apache
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
找到 DirectoryIndex 行,添加 index.php 作为默认首页:
apache
DirectoryIndex index.html index.php
- 配置文件路径:
/opt/homebrew/etc/httpd/httpd.conf(核心配置文件) - 网站根目录:
/opt/homebrew/var/www/(默认存放网页文件的位置) - 日志文件目录:
/opt/homebrew/var/log/httpd/(访问日志和错误日志) - Apache 命令路径:
/opt/homebrew/opt/httpd/bin/apachectl(用于管理服务)
语法检测
/opt/homebrew/opt/httpd/bin/apachectl configtest
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于