Skip to content

Instantly share code, notes, and snippets.

@anuragsarkar
Forked from ankurk91/xdebug-mac.md
Created June 5, 2019 09:22
Show Gist options
  • Save anuragsarkar/b85d7c5878430cd769a92fff94abcc78 to your computer and use it in GitHub Desktop.
Save anuragsarkar/b85d7c5878430cd769a92fff94abcc78 to your computer and use it in GitHub Desktop.
php xDebug on Ubuntu/Mac and phpStorm 2018

🪲 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.remote_enable = 1
xdebug.remote_port = 9000
xdebug.idekey = PHPSTORM
xdebug.show_error_trace = 1
xdebug.remote_autostart = 0
xdebug.file_link_format = phpstorm://open?%f:%l
  • 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 !!!

🪲 Install and Configure xDebug on Ubuntu for PhpStorm 🐘

  • Assuming that you have already installed php and apache
  • Install xDebug php extension
# Ubuntu 16.04,18.04 php 7.x
sudo apt-get install php-xdebug

# Ubuntu 14.04, php 5.6 
sudo apt-get install php5-xdebug
  • Edit your xdebug.ini
  • Your xdebug.ini file path should look like this
    • /etc/php/7.1/mods-available/xdebug.ini
  • Add these lines without modifying exiting
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.idekey = PHPSTORM
xdebug.show_error_trace = 1
xdebug.remote_autostart = 0
xdebug.file_link_format = phpstorm://open?%f:%l
  • 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment