關於Mac OS Monterey上的Apache/httpd的筆記

路徑,可以用which httpd確定

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/usr/sbin/http
/usr/sbin/http
/usr/sbin/http

版本

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
httpd -v
Server version: Apache/2.4.51 (Unix)
Server built: Feb 12 2022 02:40:22
# more details (Capital V)
httpd -V
httpd -v Server version: Apache/2.4.51 (Unix) Server built: Feb 12 2022 02:40:22 # more details (Capital V) httpd -V
httpd -v
Server version: Apache/2.4.51 (Unix)
Server built:   Feb 12 2022 02:40:22

# more details (Capital V)
httpd -V

重啟httpd,

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo apachectl -k restart
sudo apachectl -k restart
sudo apachectl -k restart

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[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
[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
[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,比如

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
codesign --sign "<certificate name>" --force --keychain ~/Library/Keychains/login.keychain-db /usr/local/Cellar/php/<php version>/lib/httpd/modules/libphp.so
codesign --sign "<certificate name>" --force --keychain ~/Library/Keychains/login.keychain-db /usr/local/Cellar/php/<php version>/lib/httpd/modules/libphp.so
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地址

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
grep -nir "^loadmodule.*php" /etc/apache2
grep -nir "^loadmodule.*php" /etc/apache2
grep -nir "^loadmodule.*php" /etc/apache2

在Mac OS里,apache2 conf的可能路徑是/etc/apache2/httpd.conf,可以用sudo許可權編輯

mvim /etc/apache2/httpd.conf

Document root路徑

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/Library/WebServer/Documents
/Library/WebServer/Documents
/Library/WebServer/Documents

Config file (配置文件)路徑

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/etc/apache2/httpd.conf
/etc/apache2/httpd.conf
/etc/apache2/httpd.conf

log (日誌)路徑

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cd /var/log/apache2
# in one window
tail -f error_log
# in another window
tail -f access_log
cd /var/log/apache2 # in one window tail -f error_log # in another window tail -f access_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.