- OS: Linux (Ubunutu)
- IDE: Intellij
- Find your current php version:
php -vThe result will be like X.Y.Z.
- Install php-xdebug specifically for your php version:
sudo apt install phpX.Y-xdebug- Evaluate if it has been installed correctly:
php -vYou should see something like this on the output: with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans.
- Find your
xdebugextension path:
php -i | grep extension_dirThe output will be something like: /usr/lib/php/20200930
Make sure the xdebug.so is on that folder: ls /usr/lib/php/20200930
- Open the right version of your
php.inifile:
sudo vim /etc/php/X.Y/cli/php.ini
Paste these lines to your php.ini file:
[xdebug]
zend_extension=/usr/lib/php/20200930/xdebug.so
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.start_with_request=yes-
Configure Intellij based on this link
-
One other thing missing from the step 6: Press
Alt+Ctrl+Sto open the settings menu. On theLanguages & Frameworkssection, SelectPHPand thenDebug. On the
Pre-configurationsection, press theValidatelink (on line number 1), and then on the opened window on thePath to create validation script
use the folder of your project that contains the starting file (usually thepublicfolder contains theindex.phpfile) and make sure that pressing theValidatebutton leads to all the green checks. -
Uncheck breaking at the first line of the script:
PressAlt+Ctrl+Sto open the settings menu, then on theLanguages & Frameworkssection use thePHPlanguage, select theXdebugon the menu, the on theXdebugsection make sure to uncheck these two lines:
Force break at first line when no path mapping specifiedForce break at first line when a script is outside the project
Apply and Ok.
Then also on the Run menu on the top bar, make sure to uncheck the Break at first line in PHP scripts.
-
Add
public/_intellij_phpdebug_validator.phpto your.gitignorefile. -
Start listening: Use
Start Listeningbutton on top of your IDE (phone lile button), and use a breaking point on your IDE.
Happy debugging!