brew updatebrew tap homebrew/apache
brew install httpd24
服務管理:
brew services start homebrew/apache/httpd24 # 啟動
brew services restart homebrew/apache/httpd24 # 重啟
brew services stop homebrew/apache/httpd24 # 停止
驗證:瀏覽 https://localhost:8080 看到 "It works!"
brew install mysql
brew services start mysql
首次登入:mysql -u root -p(無密碼直接 Enter),建議立即設定密碼。
推薦管理工具:Sequel Pro(免費、好用)。
brew tap homebrew/php
brew install php70 --with-httpd24
關鍵參數:--with-httpd24 確保編譯對應 Apache 2.4 模組。
錯誤:xcode-select --install 後重新 brew reinstall php70 --with-httpd24。
編輯 /usr/local/etc/apache2/2.4/httpd.conf:
# 從 `brew info php70` 獲取確切路徑
LoadModule php7_module /usr/local/opt/php70/lib/httpd/modules/libphp7.so
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html
DocumentRoot "/Users/你的用戶名/wwwdoc"
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
# 建立測試檔
echo '
重啟 Apache:brew services restart homebrew/apache/httpd24
瀏覽 https://localhost:8080/info.php 查看 PHP 7.0 資訊頁。
| 操作 | 指令 |
|---|---|
| Apache 啟動/重啟/停止 | brew services start|restart|stop homebrew/apache/httpd24 |
| MySQL 啟動/重啟/停止 | brew services start|restart|stop mysql |
| PHP 版本切換 | brew unlink php70 && brew link --force php71 |
| 查看錯誤日誌 | tail -f /usr/local/var/log/httpd/error_log |