Skip to content

Instantly share code, notes, and snippets.

@ankurk91
Last active March 9, 2024 22:20
Show Gist options
  • Save ankurk91/22e4a07be552790a9d6a063ee1bace05 to your computer and use it in GitHub Desktop.
Save ankurk91/22e4a07be552790a9d6a063ee1bace05 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 php8.2-xdebug
  • Edit your xdebug.ini
  • Your xdebug.ini file path should look like this
    • /etc/php/8.2/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
@leodstar93
Copy link

leodstar93 commented Jan 13, 2022

Hi, thank you very much, I managed to get PhpStorm 2021 to accept debugging when I mark breaking on the first line, but when I mark a non-debug breakpoint, can you please tell me that I am missing this is my debug.ini
`
Configuration for Xdebug 3

[Xdebug]
zend_extension=/usr/lib/php/20190902/xdebug.so

xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.idekey=PHPSTORM
xdebug.client_port=10003
xdebug.client_host=192.168.1.7
xdebug.file_link_format=phpstorm://open?%f:%l

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