Skip to content

Instantly share code, notes, and snippets.

@ildarkhasanshin
Forked from ankurk91/xdebug-mac.md
Created March 19, 2018 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ildarkhasanshin/c175c1970e61b839075b7d464de34c8b to your computer and use it in GitHub Desktop.
Save ildarkhasanshin/c175c1970e61b839075b7d464de34c8b to your computer and use it in GitHub Desktop.
php xDebug on Ubuntu/Mac and phpStorm 2017

🪲 Install and Configure xDebug on Ubuntu/Mac and PhpStorm 🐘

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

# Ubuntu 14.04, php 5.6 
sudo apt-get install php5-xdebug

# Mac OS with Homebrew
# brew install php<version>-xdebug
# Example for php v7.2
brew install php72-xdebug
  • Edit your xdebug.ini
  • Your xdebug.ini paths should look like this
    • Ubuntu /etc/php/7.1/mods-available/xdebug.ini
    • macOS /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini
  • You can run locate *xdebug.ini to find xdebug.ini file location
  • Add these lines without modifying exiting lines
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
  • Above configs are bare minimum, read all options here
  • Restart the apache server to reflect changes
# Ubuntu
sudo service apache2 restart

# MacOS
sudo apachectl 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 virtual host 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 this chrome extension

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

  • Done, enjoy debugging !!!


Disable xdebug (Ubuntu)

sudo phpdismod xdebug

Enable xdebug back (Ubuntu)

sudo phpenmod xdebug

Disable xdebug for commandline only (Ubuntu)

sudo phpdismod -s cli xdebug

Troubleshooting

  • Try to change the port to something else, for example 18000
  • Enable Break at first line in phpStorm php debug settings
  • Set xdebug.remote_autostart to 1 if you don't want to bother with browser extensions

Resources

Not a big fan of phpStorm?

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