Skip to content

Instantly share code, notes, and snippets.

Forked from ankurk91/
Last active July 5, 2018 20:26
Show Gist options
  • Save legomolina/a597d7600836160866454db2c33279bb to your computer and use it in GitHub Desktop.
Save legomolina/a597d7600836160866454db2c33279bb 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 v5.6
brew install php56-xdebug
  • Now edit your php.ini (for me it was /etc/php/7.0/apache2/php.ini) and add these lines at last
  • You can run locate php.ini to find php.ini file location
xdebug.remote_enable = 1
xdebug.remote_port = 9000 ;take note of this
xdebug.idekey = PHPSTORM
xdebug.max_nesting_level = 512
xdebug.file_link_format = phpstorm://open?%f:%l
  • Above config is bare minimum, read all options here
  • Make sure path is correct in above configuration
  • To find the file path; run this command
  • Above command will return the correct path to file

  • Now check php version

php --version
  • Above command should return like this
PHP 7.0.15-0ubuntu0.16.04.4 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.15-0ubuntu0.16.04.4, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
  • Notice the Xdebug version in last line
  • Restart apache server to reflect changes
# Ubuntu
sudo service apache2 restart

# Mac OS
sudo apachectl restart
  • Configure phpStorm
  • Go through - Settings >> Languages & Frameworks >> PHP
  • Lets set php Interpreter, to do so; click on three dots [...] button
  • On the new window; click on plus [+] button and select /usr/bin/php from suggestion popup
  • Save and close this window
  • Now, on the Settings window; select the Interpreter you just created then save and close

Note about port: Maybe phpStorm default port for xDebug is other than 9000. To check this and/or configure it:

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

  • Scroll to the Xdebug section

  • Check that Debug port is the same you have in your php.ini.

  • Start debuging

  • In PhpStorm create some breakpoints in your project

  • 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 like this, 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

sudo phpdismod -s cli xdebug

Sublime Text 3 user ?


Copy link

Added note about the port.

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