1. 程式人生 > >使用PHPStorm實現遠端除錯

使用PHPStorm實現遠端除錯

步驟1:在伺服器上安裝xdebug,並配置
-> pecl install xdebug
-> 修改php.ini,新增內容
```  shell
zend_extension=xdebug.so
;允許遠端除錯
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
;如果開啟此,將忽略下面的 xdebug.remote_host 的引數。 
xdebug.remote_connect_back=1
;(注意這裡是,客戶端的ip是IDE的機器的ip,不是你的web server的ip)
;xdebug.remote_host = 192.168.33.21    
xdebug.remote_port=9001
xdebug.remote_log = "/tmp/xdebug"
;偵錯程式的關鍵字
xdebug.idekey="PHPSTORM"
;函式跟蹤
xdebug.auto_trace = on
xdebug.collect_params=on
xdebug.collect_return=on
xdebug.trace_output_dir = /tmp/xdebug
xdebug.trace_output_name = trace.%c
;瓶頸分析
xdebug.profiler_enable=on
xdebug.profiler_enable_trigger = on
xdebug.profiler_output_dir = /tmp/xdebug
xdebug.profiler_output_name = cachegrind.out.%p
```


步驟2:在preferences/Deployment新增一個server
-> 在Connection專案裡填寫Sftp host、Port、Root Path等新增資訊,新增完了點選Test 
SFTP connection
->在Mappings裡新增本地檔案和遠端檔案的對映,並填寫Web path,填“/”即可


步驟3:修改preferences/Language & Frameworks/PHP裡的配置
-> 修改Development environment,修改PHP language level和Interpreter(php可執行檔案的二進位制路徑)
-> 修改Debug子項的配置將xdebug Debug port改為9001
-> 修改Debug子項中DBGP Proxy的配置:IDE Key(例PHPStorm)、Host(遠端IP)、Port(xdebug監聽埠)


步驟4:在Run/Edit configurations匯入部署的server
新增“+”號時選擇PHP Web Application


步驟5:開始除錯
點選Run/Debug