安裝 WAMP 後訪問 https://localhost/phpmyadmin/ 提示:
403 Forbidden
You don't have permission to access /phpmyadmin/ on this server.
WAMP 為 phpMyAdmin 配置了獨立的 <Directory> 權限控制,默認僅允許 127.0.0.1 訪問。當通過 localhost 訪問時解析為 IPv6 ::1 或主機名,不匹配 127.0.0.1,導致拒絕。
httpd.confC:\wamp\alias\phpmyadmin.conf(推薦,專用別名配置)Alias /phpmyadmin "c:/wamp/apps/phpmyadmin3.5.1/"
<Directory "c:/wamp/apps/phpmyadmin3.5.1/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
<IfDefine APACHE24>
Require all granted
<Else>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
Allow from localhost
</IfDefine>
</Directory>
關鍵修改: 將 Allow from 127.0.0.1 改為 Allow from all(Apache 2.2),或改為 Require all granted(Apache 2.4)。建議保留 Allow from ::1 Allow from localhost 兼容 IPv6/主機名。
WAMP 托盤圖標 → Restart All Services,圖標變綠。
| 場景 | Apache 2.2 (WAMP 2.x) | Apache 2.4 (WAMP 3.x+) |
|---|---|---|
| 允許所有 | Order Allow,Deny Allow from all | Require all granted |
| 僅本地 | Order Deny,Allow Deny from all Allow from 127.0.0.1 ::1 localhost | Require local |
| 指定 IP 段 | Allow from 192.168.1 | Require ip 192.168.1 |
<Directory "c:/wamp/apps/phpmyadmin3.5.1/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
# Apache 2.4
Require ip 127.0.0.1 ::1 192.168.0.0/16 10.0.0.0/8 172.16.0.0/12
# Apache 2.2
# Order Deny,Allow
# Deny from all
# Allow from 127.0.0.1 ::1 localhost
# Allow from 192.168.0.0/16
# Allow from 10.0.0.0/8
# Allow from 172.16.0.0/12
</Directory>
alias/phpmyadmin.conf 而非主 httpd.conf 中的其他 <Directory>。httpd.conf 是否包含 Include "c:/wamp/alias/*.conf",且未被註釋。netstat -an | findstr :80)。Alias /mysecret_pma_abc123 "..." 避免掃描器發現。<Directory "...">
...
AuthType Basic
AuthName "phpMyAdmin Restricted"
AuthUserFile "c:/wamp/.htpasswd"
Require valid-user
</Directory>