Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
php xDebug on Ubuntu/Mac and phpStorm 2019

๐Ÿž 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 v7.x
pecl install xdebug

# If you have php v5.6
# pecl install xdebug-2.5.5

# 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.2/conf.d/ext-xdebug.ini
  • Add these lines by overwriting exiting
;zend_extension="/usr/local/Cellar/php@7.2/7.2.13/pecl/20170718/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.2/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.2/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/

@Riro4ever

This comment has been minimized.

Copy link

commented Aug 30, 2019

Great!
Thank you

@JackXuXin

This comment has been minimized.

Copy link

commented Oct 15, 2019

command line: sudo pecl install xdebug
env

macos 10.15
PEAR Version: 1.10.9
PHP Version: 7.3.8
Zend Engine Version: 3.3.8
Running on: Darwin 192.168.0.120 19.0.0 Darwin Kernel Version 19.0.0: Wed Sep 25 20:18:50 PDT 2019; root:xnu-6153.11.26~2/RELEASE_X86_64 x86_64

error:

guest@192 CommandLineTools % sudo pecl install xdebug
downloading xdebug-2.7.2.tgz ...
Starting to download xdebug-2.7.2.tgz (230,987 bytes)
.................................................done: 230,987 bytes
69 source files, building
running: phpize
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
building in /private/tmp/pear/install/pear-build-rootbiObks/xdebug-2.7.2
running: /private/tmp/pear/install/xdebug/configure --with-php-config=/usr/bin/php-config
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-apple-darwin19.0.0
checking host system type... x86_64-apple-darwin19.0.0
checking target system type... x86_64-apple-darwin19.0.0
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
checking for PHP extension directory... /usr/lib/php/extensions/no-debug-non-zts-20180731
checking for PHP installed headers prefix... /usr/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking whether to enable Xdebug support... yes, shared
checking whether to enable Xdebug developer build flags... no
checking Check for supported PHP versions... supported (7.3.8)
checking for gettimeofday... yes
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking netinet/in.h usability... yes
checking netinet/in.h presence... yes
checking for netinet/in.h... yes
checking poll.h usability... yes
checking poll.h presence... yes
checking for poll.h... yes
checking sys/poll.h usability... yes
checking sys/poll.h presence... yes
checking for sys/poll.h... yes
checking for cos in -lm... yes
checking for ld used by cc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 196608
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking if cc supports -fno-rtti -fno-exceptions... yes
checking for cc option to produce PIC... -fno-common
checking if cc PIC flag -fno-common works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin19.0.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/sh /private/tmp/pear/install/pear-build-rootbiObks/xdebug-2.7.2/libtool --mode=compile cc   -I. -I/private/tmp/pear/install/xdebug -DPHP_ATOM_INC -I/private/tmp/pear/install/pear-build-rootbiObks/xdebug-2.7.2/include -I/private/tmp/pear/install/pear-build-rootbiObks/xdebug-2.7.2/main -I/private/tmp/pear/install/xdebug -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /private/tmp/pear/install/xdebug/xdebug.c -o xdebug.lo
mkdir .libs
 cc -I. -I/private/tmp/pear/install/xdebug -DPHP_ATOM_INC -I/private/tmp/pear/install/pear-build-rootbiObks/xdebug-2.7.2/include -I/private/tmp/pear/install/pear-build-rootbiObks/xdebug-2.7.2/main -I/private/tmp/pear/install/xdebug -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/install/xdebug/xdebug.c  -fno-common -DPIC -o .libs/xdebug.o
/private/tmp/pear/install/xdebug/xdebug.c:25:10: fatal error: 'php.h' file not found
#include "php.h"
         ^~~~~~~
1 error generated.
make: *** [xdebug.lo] Error 1
ERROR: `make' failed
@ankurk91

This comment has been minimized.

Copy link
Owner Author

commented Oct 15, 2019

@JackXuXin update your xcode command line tools

@JackXuXin

This comment has been minimized.

Copy link

commented Oct 15, 2019

@JackXuXin update your xcode command line tools

i have updated xcode command line tools

@ankurk91

This comment has been minimized.

Copy link
Owner Author

commented Oct 15, 2019

@JackXuXin post your issue on stackoverflow, you will get better support there.

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.