PhpStorm 使用SSH建立在Bitnami EC2上的WordPress XDebug

Sebastian Hsu
Jul 27, 2017 · 4 min read

此篇參考

在WordPress的開發上有時候會使用AWS上的Bitnami出的AMI,剛好最近需要使用PhpStorm的debugger,特此記錄一下如何使用PhpStorm透過xdebug連到Bitnami的EC2。

  1. 按照https://confluence.jetbrains.com/display/PhpStorm/WordPress+Development+using+PhpStorm 啟動與WordPress的整合

2. ssh到server端,安裝xdebug,我使用的是Bitnami的WordPress AMI

pecl install xdebug

3. 修改 /opt/bitnami/php/etc/php.ini ,加入以下程式碼

4. 重啟server,在許多地方看到重啟Apache就好,但是實際的經驗是重開沒有用,所以還是需要重新啟動整台server才行

5. 設定ssh tunnel,你必須要使用putty,在輸入一般連線資訊後,到 Connection > SSH > Tunnels,設定

Source port:9000
Destination:localhost:9000
勾選「Remote」完按下「Add」

6. 在PhpStorm中選取Run > Start Listening for PHP Debug Connections,你會在你的editor看到這樣的圖示

7. 在你想要加中斷點的地方加中斷點,如果一開始不曉得在哪,也可以選取 Run > Break at first line in PHP scripts

8. 到 PhpStorm bookmarklets generator 安裝debug的 bookmarklets,開起網頁後在Xdebug下按下Generate

把「Start debugger」以及「Stop debugger」用拖拉的加到瀏覽器的bookmark中,如果你瀏覽器沒有把bookmark打開要記得打開

9. 打開你要測試的網址,在bookmark中按下 Start debugger,然後重新整理網頁,此時你會看到PhpStorm跳出一個視窗,跟你說有遠端的xdeubg的請求,確認之後按下「Accept」即可。(下圖是截自官方文件,因為我自己的popup被我按掉了XD)

此時就可以用debugger來debug遠端EC2上的WordPress囉!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade