Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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/php@7.1/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
@thekavish

This comment has been minimized.

Copy link

commented Mar 26, 2017

Thanks a lot!

@ghost

This comment has been minimized.

Copy link

commented Apr 20, 2017

Thanks

@volosgoto

This comment has been minimized.

Copy link

commented Apr 27, 2017

Thanks help's me a lot!

@Arbagen

This comment has been minimized.

Copy link

commented May 23, 2017

Thanks

@ghost

This comment has been minimized.

Copy link

commented Jul 1, 2017

thank you so much for all your in.detail info ... iam just a hobby coder and dont know much about ubuntu nor phpstorm xdebug etc pp (iam already retired and find it relaxing to learn how to code for fun while my darling wife is at work) and did everything as listed; still it doesnt work for some google crome error ... can you pls help me with that ?

@ankurk91

This comment has been minimized.

Copy link
Owner Author

commented Jul 2, 2017

@Vogan1972
Did you followed all steps ?
What is the exact error in Google chrome ?

@ghost

This comment has been minimized.

Copy link

commented Jul 2, 2017

@ankurk91
when i try to debug some code it says that some googlecrome thingy aint installed even tho i have all browser other then the installed firefox unchecked ... also i have trouble editing the ini file as it's read.only so i learned i have to start my editor from console with the sudo command and then i changed it; saved it; restarted all and the problem was still there ... iam sure is something because iam such a noob on ubunto/Linux in general ... on my win10 gameing pc i got it right on 1st attempt ...

ty for takeing the time on a sunday morning and answering my silly helplessness :)

@ankurk91

This comment has been minimized.

Copy link
Owner Author

commented Jul 2, 2017

@Vogan1972
The browsers selection in PHP storm has nothing to do with xdebug.
How are you accessing your website ? Virtual Host ?

@ghost

This comment has been minimized.

Copy link

commented Jul 5, 2017

@ankurk91

yes sir; sudo service apache2 and command ...

iam sorry that it took me so long to reply i been out of town

@soubinan

This comment has been minimized.

Copy link

commented Jul 6, 2017

@ankurk91 you save my life

@ghost

This comment has been minimized.

Copy link

commented Jul 14, 2017

@ankurk91 got it working ... thank you so very much!!

@naumanahmad17

This comment has been minimized.

Copy link

commented Aug 3, 2017

Thanks you
๐Ÿ‘ ๐Ÿ‘

@ilyasf

This comment has been minimized.

Copy link

commented Aug 25, 2017

Thats work fine for me) but what's about zend debugger? Is it better?

@ankurk91

This comment has been minimized.

Copy link
Owner Author

commented Aug 26, 2017

@ilyasf
Never heard of

@MaximStrutinskiy

This comment has been minimized.

Copy link

commented Sep 13, 2017

Thanks !

@SamirSouzaSys

This comment has been minimized.

Copy link

commented Nov 11, 2017

Thank you, Help me!

@willianmano

This comment has been minimized.

Copy link

commented Nov 14, 2017

Awesome! Thank you very much!

@mildlyautistic

This comment has been minimized.

Copy link

commented Nov 17, 2017

Thanks Ankur.
Made my day!!

@juandavilau

This comment has been minimized.

Copy link

commented Nov 17, 2017

Thanks!!

@lugamb1

This comment has been minimized.

Copy link

commented Dec 19, 2017

Awesome. Thank you

@legomolina

This comment has been minimized.

Copy link

commented Jan 18, 2018

Added a note about the port, in my case, phpStorms sets the default port to 10000
https://gist.github.com/legomolina/a597d7600836160866454db2c33279bb

@ankurk91

This comment has been minimized.

Copy link
Owner Author

commented Jan 19, 2018

@legomolina
Thanks, yes ports should be same in both places

@oKba2k

This comment has been minimized.

Copy link

commented Feb 6, 2018

Finally its working. Thank you a lot!

@RndRss

This comment has been minimized.

Copy link

commented Feb 17, 2018

tks, works fine

@victorcpereira

This comment has been minimized.

Copy link

commented May 4, 2018

Great!! Thank you!

@Xirdion

This comment has been minimized.

Copy link

commented Jun 20, 2018

Perfect! Thank you.

@olehi94

This comment has been minimized.

Copy link

commented Dec 10, 2018

Thanks a lot!

@riju-das

This comment has been minimized.

Copy link

commented Mar 24, 2019

thanks a lot!

@olivedev

This comment has been minimized.

Copy link

commented Apr 25, 2019

I love xdebug, but I prefer it to use with VSCode. VSCode with the combination of Xdebug makes debugging in PHP really easy and awesome. Check it out here: https://www.cloudways.com/blog/php-debug-with-xdebug/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You canโ€™t perform that action at this time.