Skip to content

Instantly share code, notes, and snippets.

@majidalaeinia
Last active January 11, 2022 11:22
Show Gist options
  • Select an option

  • Save majidalaeinia/44e6555232e45ddfff62be55dfabfacf to your computer and use it in GitHub Desktop.

Select an option

Save majidalaeinia/44e6555232e45ddfff62be55dfabfacf to your computer and use it in GitHub Desktop.

Installing Xdebug on Intellij

  • OS: Linux (Ubunutu)
  • IDE: Intellij
  1. Find your current php version:
php -v

The result will be like X.Y.Z.

  1. Install php-xdebug specifically for your php version:
sudo apt install phpX.Y-xdebug
  1. Evaluate if it has been installed correctly:
php -v

You should see something like this on the output: with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans.

  1. Find your xdebug extension path:
php -i | grep extension_dir

The output will be something like: /usr/lib/php/20200930 Make sure the xdebug.so is on that folder: ls /usr/lib/php/20200930

  1. Open the right version of your php.ini file:
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
  1. Configure Intellij based on this link

  2. One other thing missing from the step 6: Press Alt+Ctrl+S to open the settings menu. On the Languages & Frameworks section, Select PHP and then Debug. On the
    Pre-configuration section, press the Validate link (on line number 1), and then on the opened window on the Path to create validation script
    use the folder of your project that contains the starting file (usually the public folder contains the index.php file) and make sure that pressing the Validate button leads to all the green checks.

  3. Uncheck breaking at the first line of the script:
    Press Alt+Ctrl+S to open the settings menu, then on the Languages & Frameworks section use the PHP language, select the Xdebug on the menu, the on the Xdebug section make sure to uncheck these two lines:

  • Force break at first line when no path mapping specified
  • Force 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.

  1. Add public/_intellij_phpdebug_validator.php to your .gitignore file.

  2. Start listening: Use Start Listening button on top of your IDE (phone lile button), and use a breaking point on your IDE.

Happy debugging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment