Skip to content

Instantly share code, notes, and snippets.

@smarteist
Last active June 11, 2021 05:11
Show Gist options
  • Select an option

  • Save smarteist/0d03c1eb7dcf5e507a8d122334af4bdf to your computer and use it in GitHub Desktop.

Select an option

Save smarteist/0d03c1eb7dcf5e507a8d122334af4bdf to your computer and use it in GitHub Desktop.
PHP xDebug on Linux/Mac and phpStorm

Install and Configure xDebug πŸͺ² on Linux for PhpStorm 🐘

  • Assuming that you have already installed php and apache
  • Install xDebug php extension

# Arch Linux , Manjaro
sudo pacman -Sy xdebug

# Ubuntu 16.04,18.04
sudo apt-get install php-xdebug
  • Edit your xdebug.ini
  • Your xdebug.ini file path (according to your php version) should look like this
    • /etc/php/7.1/mods-available/xdebug.ini
  • Add these lines without modifying exiting
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_port = 9000
xdebug.idekey = PHPSTORM
xdebug.show_error_trace = 1
xdebug.file_link_format = phpstorm://open?%f:%l
xdebug.max_nesting_level=1000
  • Restart the apache server to reflect changes
sudo service apache2 restart
  • Configure phpStorm

  • Go through - Settings >> Languages & Frameworks >> PHP >> Debug

  • Check that 'Debug port' is the same you have in your xdebug.ini. In our case it was 9000.

  • Save and close the Settings Dialog

  • Start debugging

  • Create some breakpoints in your project

  • Make sure those breakpoints gets executed when your visit your website in browser.

  • Start listener by clicking on the telephone πŸ“ž button on top toolbar

  • If you can't find telephone button; then go through menus - Run -> Start listening for PHP Debug Connections

  • In your browser access your project url like this

http://localdomain.test/?XDEBUG_SESSION_START=1
  • OR use bookmarks

  • OR use chrome extension

  • You should see a popup window in PhpStorm , click Accept connection

  • Done, enjoy debugging !!!


Disable xdebug

sudo phpdismod xdebug

Enable xdebug back

sudo phpenmod xdebug

Disable xdebug for commandline only

sudo phpdismod -s cli xdebug

Install and Configure xDebug πŸͺ² on MacOS for PhpStorm 🐘

⚠️ This guide only applies to Homebrew v1.6+

  • Check your version brew --version before proceeding

  • Assuming that you have already installed php and apache via Homebrew v1.6+

  • Install xDebug php extension

pecl channel-update pecl.php.net
pecl clear-cache

# If you have php v5.6
pecl install xdebug-2.5.5
# If you have php v7.x
pecl install xdebug

pecl clear-cache
  • Edit your ext-xdebug.ini
  • Your ext-xdebug.ini file path should look like this (depends on php version installed)
    • /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini
  • Add these lines by overwriting exiting
;zend_extension="/usr/local/Cellar/[email protected]/7.1.21/pecl/20160303/xdebug.so"
zend_extension="xdebug.so"
xdebug.mode=debug
xdebug.client_port = 9000
xdebug.idekey = PHPSTORM
xdebug.show_error_trace = 1
xdebug.file_link_format = phpstorm://open?%f:%l
xdebug.max_nesting_level=1000
  • Update your php.ini

  • When installing xdebug extension using pecl, it also updates our php.ini file, but we don't need that.

  • Find your php.ini file, file path should look like this (depends on php version installed)

    • /usr/local/etc/php/7.1/php.ini
  • Remove any occurrence of zend_extension="xdebug.so" from this file

  • Restart the apache server to reflect changes

sudo apachectl -k restart
  • Configure phpStorm

  • Go through - Settings >> Languages & Frameworks >> PHP >> Debug

  • Check that 'Debug port' is the same you have in your ext-xdebug.ini. In our case it was 9000.

  • Save and close the Settings Dialog

  • Start debugging

  • Create some breakpoints in your project

  • Make sure those breakpoints gets executed when your visit your website in browser.

  • Start listener by clicking on the telephone πŸ“ž button on top toolbar

  • If you can't find telephone button; then go through menus - Run -> Start listening for PHP Debug Connections

  • In your browser access your project url like this

http://localdomain.test/?XDEBUG_SESSION_START=1
  • OR use bookmarks

  • OR use chrome extension

  • You should see a popup window in PhpStorm , click Accept connection

  • Done, enjoy debugging !!!

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