2021-01-21

iItelliJ 設定PHP XDEBUG環境

 一、安裝composer、php-cgi(注意,必須是cgi,不能用cli或fpm)、php-xdebug
sudo apt-get install php-cgi php-xdebug
sudo curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chown root.root /usr/local/bin/composer
sudo chmod 755 /usr/local/bin/composer

二、修改xdebug設定
sudo vi /etc/php/7.2/cgi/conf.d/20-xdebug.ini
加上
xdebug.remote_enable=1

php-cgi --version //須出現xdebug字眼
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans

三、chrome或firefox安裝xdebug plugin
https://www.jetbrains.com/help/idea/2020.3/browser-debugging-extensions.html
擴充功能選項的IDE Key選擇PHPSTORM

四、修改IntelliJ的language & frameworks / PHP 設定
新增 /usr/bin/php-cgi

五、執行選單 Run / Web Server Debug Validation,看是否能正常debug

若使用intellij內建的web server + php-cgi,可能會沒有$_SERVER['SERVER_NAME'] 造成無法正常透過瀏覽器debug,下面的ref有解法但不一定有用,似乎是intellij的bug,似乎還是得換成nginx或apache才能解決,若用外部server,須到 language & frameworks / PHP / Servers及build,excution,deployment->Deployment去新增對應的server


ref:
https://www.jetbrains.com/help/idea/2020.3/configuring-xdebug.html
https://www.jetbrains.com/help/idea/2020.3/zero-configuration-debugging.html
https://youtrack.jetbrains.com/issue/WI-54542
https://stackoverflow.com/questions/23344106/php-storm-debugging-creates-empty-server-definitions
https://www.cnblogs.com/Renyi-Fan/p/9117895.html