Skip to content

Instantly share code, notes, and snippets.

@chkilel
Forked from ankurk91/xdebug-mac.md
Created August 12, 2021 12:05
Show Gist options
  • Save chkilel/9a99739468a5266ac4c882030665e69c to your computer and use it in GitHub Desktop.
Save chkilel/9a99739468a5266ac4c882030665e69c to your computer and use it in GitHub Desktop.
php xDebug v3 on Ubuntu/Mac and phpStorm

🪲 Install and Configure xDebug v3 on MacOS for PhpStorm 🐘

  • Assuming that you have already installed php and apache via Homebrew

  • Install xDebug php extension

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

pecl install xdebug

# Optional command
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.4/conf.d/ext-xdebug.ini
  • Add these lines by overwriting exiting
# Configuration for Xdebug 3
[Xdebug]
;zend_extension="/usr/local/Cellar/php@742/7.4.11/pecl/20170718/xdebug.so"
zend_extension="xdebug.so"

xdebug.mode=debug,develop
xdebug.start_with_request=default
xdebug.idekey=PHPSTORM
xdebug.client_port=9003
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.4/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 >> PHP >> Debug

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

  • 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

  • Use chrome extension

  • Configure this chrome extension and set IDE Key to PHPSTORM

  • Visit your website

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

  • Done, enjoy debugging !!!

🪲 Install and Configure xDebug v3 on Ubuntu for PhpStorm 🐘

  • Assuming that you have already installed php and apache
  • Install xDebug php extension
sudo apt-get install php7.4-xdebug
  • Edit your xdebug.ini
  • Your xdebug.ini file path should look like this
    • /etc/php/7.4/mods-available/xdebug.ini
  • Add these lines without modifying exiting
# Configuration for Xdebug 3
[Xdebug]
zend_extension="xdebug.so"

xdebug.mode=debug,develop
xdebug.start_with_request=default
xdebug.idekey=PHPSTORM
xdebug.client_port=9003
xdebug.file_link_format=phpstorm://open?%f:%l
  • Restart the apache server to reflect changes
sudo service apache2 restart
  • Configure phpStorm

  • Go through - Settings >> PHP >> Debug

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

  • 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

  • Use chrome extension

  • Configure this chrome extension and set IDE Key to PHPSTORM

  • Visit your website

  • 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