關於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.