macOS 內建 Apache Web 伺服器,無需額外安裝即可開展 PHP 開發。以下步驟幫助你快速驗證服務狀態。
myTestFile.html,內容僅需一行:<p>My web server is working.</p>/Users/你的用戶名/Sites/在瀏覽器輸入以下 URL(預設端口 80):
https://localhost/~你的用戶名/myTestFile.html
預設 Apache 不處理 PHP,需手動修改 /etc/apache2/httpd.conf:
#LoadModule php5_module libexec/apache2/libphp5.so,移除行首 # 註釋。DirectoryIndex 指令中加入 index.php。sudo apachectl restart。在 Sites 目錄建立 info.php:
<?php phpinfo(); ?>
瀏覽器訪問 https://localhost/~用戶名/info.php,若顯示 PHP 詳細資訊頁,即表示環境已就緒,可正式開發。