WAMP (Windows + Apache + MySQL + PHP) 一鍵安裝包是 Windows 平台最快上手的 PHP 開發環境。本文以 WampServer 3.0.6 64-bit 為例,涵蓋安裝、專案目錄、虛擬主機、局域網存取、常見錯誤排解。
D:\wamp64 (避免 C 盤空間不足、權限問題)。msvcr110.dll → 先安裝 Visual C++ 2012 Redistributable (vcredist_x64.exe)。D:\wamp64\www。D:\wamp64\www\myproject,瀏覽器訪問 https://localhost/myproject/。D:\wamp64\bin\apache\apache2.4.23\conf\httpd.conf:DocumentRoot "D:/wamp64/www" → 改為你的目錄 (正斜線)。<Directory "D:/wamp64/www"> 路徑。D:\wamp64\bin\apache\apache2.4.23\conf\extra\httpd-vhosts.conf:DocumentRoot "D:/wamp64/www" 同步修改。<?php
// D:\wamp64\www\test\test.php
echo 'Hello World!';
瀏覽器開啟 https://localhost/test/test.php,顯示 Hello World! 即成功。
httpd-vhosts.conf,末尾新增:
<VirtualHost *:80>
ServerName www.test.local
ServerAlias test.local
DocumentRoot "D:/wamp64/www/test"
<Directory "D:/wamp64/www/test">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
DirectoryIndex index.php index.html
</Directory>
</VirtualHost>
C:\Windows\System32\drivers\etc\hosts (需管理員權限編輯)127.0.0.1 www.test.localhttps://www.test.local/ 存取。httpd.conf,找到 <Directory "${INSTALL_DIR}/www"> 區塊:AllowOverride allRequire all granted (Apache 2.4 語法,舊版為 Order allow,deny / Allow from all)httpd-vhosts.conf 中對應 <Directory> 區塊。https://你的區網IP/ 或 https://你的區網IP/專案資料夾/。WAMP 圖示左鍵 → PHP → Version → 選擇 5.6.25 或 7.0.10 (需重啟 Apache)。
| 現象 | 可能原因 | 解決 |
|---|---|---|
| WAMP 圖示持續橙色/紅色 | Apache/MySQL 未啟動 | 檢查 80/3306 埠被佔用 (Skype、IIS、VMware) → netstat -ano | findstr :80 → 終止佔用進程或修改 Apache 埠 |
| Forbidden 403 | Require 設定錯誤 | 確認 httpd.conf/vhosts.conf Directory 區塊有 Require all granted |
| PHP 錯誤不顯示 | php.ini 設定 | 開啟 display_errors=On, error_reporting=E_ALL |
| MySQL 連線失敗 | 密碼/權限 | phpMyAdmin 根帳號預設無密碼,建議設定 root 密碼並建立專用帳號 |
完成上述設定,您即擁有一個功能完整、支援虛擬主機、可區網存取的 PHP 本地開發環境,可專注於程式碼撰寫而非環境折騰。