关于Mac OS Monterey上的Apache/httpd的笔记

路径,可以用which httpd确定

/usr/sbin/http

版本

httpd -v
Server version: Apache/2.4.51 (Unix)
Server built:   Feb 12 2022 02:40:22

# more details (Capital V)
httpd -V

重启httpd,

sudo apachectl -k restart

加-k会有更多信息。比如PHP需要code sign,不加就不告诉你

[Mon Jun 20 23:42:05.630597 2022] [so:error] [pid 78750] AH06665: No code signing authority for module at /usr/local/Cellar/php/8.1.1/lib/httpd/modules/libphp.so specified in LoadModule directive.
httpd: Syntax error on line 190 of /private/etc/apache2/httpd.conf: Code signing absent - not loading module at: /usr/local/Cellar/php/8.1.1/lib/httpd/modules/libphp.so

在Monterey里,加载PHP需要code sign。可以参考这篇文章

如果PHP版本更新了,比如用了brew update,那么需要对新版本的libphp 进行 code sign。

如果Mac电脑重启了,也需要codesign,比如

codesign --sign "<certificate name>" --force --keychain ~/Library/Keychains/login.keychain-db /usr/local/Cellar/php/<php version>/lib/httpd/modules/libphp.so

需要根据php安装改变上面libphp.so的路径。有时Mac上面用brew安装的php升级了,也需要修改上面的<php version>。

查找apache2 config 里面用的libphp.so地址

grep -nir "^loadmodule.*php" /etc/apache2

在Mac OS里,apache2 conf的可能路径是/etc/apache2/httpd.conf,可以用sudo权限编辑

mvim /etc/apache2/httpd.conf

Document root路径

/Library/WebServer/Documents

Config file (配置文件)路径

/etc/apache2/httpd.conf

log (日志)路径

cd /var/log/apache2

# in one window
tail -f error_log

# in another window
tail -f access_log

本文链接

Leave a Comment

Your email address will not be published.