1. 程式人生 > >搭建PHP環境(XAMPP+PhpStorm),並設定斷點除錯(XDebug+Chrome)

搭建PHP環境(XAMPP+PhpStorm),並設定斷點除錯(XDebug+Chrome)

二、安裝XAMPP
網址:XAMPP

如圖所示:預設情況下,Server裡面全部選中,由於本人電腦上已經安裝過MySQL,因此這裡取消了MySQL選項。本人的安裝路徑是F:\software;
這裡寫圖片描述

安裝之後的介面如下:
這裡寫圖片描述

三、安裝XDebug
3.1 確定需要的XDebug版本
3.1.1 啟動XMAPP的Apache
這裡寫圖片描述

3.1.4 分析後的結果,顯示出了對應的XDebug版本,及相關操作
這裡寫圖片描述

3.2 安裝3.1.4的分析結果,下載XDebug,並將其複製到F:\software\xampp\php\ext資料夾下。

3.3 修改xmapp的php.ini檔案,在php.ini末尾加入以下內容

[XDebug]
zend_extension = "F:\software\xampp\php\ext\php_xdebug-2.6.0-7.2-vc15.dll"
xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "F:\software\xampp\tmp"
xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_enable = On
xdebug.remote
_handler = "dbgp" xdebug.remote_host = localhost xdebug.remote_mode = "req" xdebug.remote_port = 9000 xdebug.trace_output_dir = "F:\software\xampp\tmp" xdebug.remote_log = "F:\software\xampp\log" xdebug.idekey= PHPSTROM

四、配置PhpStorm
4.1 進入File>Settings>PHP,CLI Interpreter填選F:\software\xampp\php\php.exe
這裡寫圖片描述

4.2 進入File>Settings>PHP>Servers,這裡要填寫伺服器端的相關資訊,name填localhost(隨意填寫),host填localhost,port填80,debugger選XDebug
這裡寫圖片描述

4.3 進入File>Settings>PHP>Debug,看到XDebug選項卡,port填9000(與XDebug中配置的埠一致),其他預設
這裡寫圖片描述

4.4 進入File>Settings>PHP>Debug>DBGp Proxy,IDE key 填 PHPSTORM,host 填localhost,port填9000
這裡寫圖片描述

4.5 驗證XDebuger的安裝,進入File>Settings>PHP,點選Validate
這裡寫圖片描述

4.6 進入如下頁面,其中Path to create validation script選項填寫F:\software\xampp\htdocs;Url to validation script選項填寫http://localhost:80,成功後的介面如下
這裡寫圖片描述

五、配置Chrome,配置Xdebug helper
5.1 直接在chrome://extensions/中獲取更多擴充套件程式進行下載,由於本人無法翻牆,此方法行不通

5.2 下載Xdebug helper;
網址:Chrome外掛網

5.3 把Xdebug helper程式載入到Chrome,直接將下載的crx檔案拖到chrome://extensions/頁面即可,具體參考怎麼在谷歌瀏覽器中安裝.crx副檔名的離線Chrome外掛?

5.4 在chrome://extensions/頁面,點選Xdebug helper擴充套件程式下的“選項”
這裡寫圖片描述

5.5 設定IDE key 為PhpStrom
這裡寫圖片描述

六、新建專案並部署
6.1 專案存放在F:\software\xampp\htdocs目錄下
這裡寫圖片描述

6.2 點選 Edit Configurations,Server選項選擇test伺服器,Start URL選項填寫/test/index.php
這裡寫圖片描述

6.3 開啟監聽模式
這裡寫圖片描述

6.4 點選debug,執行成功
這裡寫圖片描述