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
Copy link

ghost 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
Copy link
Author

ankurk91 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 ?

Copy link

ghost 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
Copy link

soubinan commented Jul 6, 2017

@ankurk91 you save my life

Copy link

ghost commented Jul 14, 2017

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

@naumanahmad17
Copy link

Thanks you
👍 👍

@ilyasf
Copy link

ilyasf commented Aug 25, 2017

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

@ankurk91
Copy link
Author

@ilyasf
Never heard of

@MaximStrutinskiy
Copy link

Thanks !

@SamirSouzaSys
Copy link

Thank you, Help me!

@willianmano
Copy link

Awesome! Thank you very much!

@mildlyautistic
Copy link

Thanks Ankur.
Made my day!!

@juandavilau
Copy link

Thanks!!

@lugamb1
Copy link

lugamb1 commented Dec 19, 2017

Awesome. Thank you

@legomolina
Copy link

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

@ankurk91
Copy link
Author

ankurk91 commented Jan 19, 2018

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

@oKba2k
Copy link

oKba2k commented Feb 6, 2018

Finally its working. Thank you a lot!

@RndRss
Copy link

RndRss commented Feb 17, 2018

tks, works fine

@victorcpereira
Copy link

Great!! Thank you!

@Xirdion
Copy link

Xirdion commented Jun 20, 2018

Perfect! Thank you.

@olehi94
Copy link

olehi94 commented Dec 10, 2018

Thanks a lot!

Copy link

ghost commented Mar 24, 2019

thanks a lot!

@Riro4ever
Copy link

Great!
Thank you

@JackXuXin
Copy link

JackXuXin 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
Copy link
Author

@JackXuXin update your xcode command line tools

@JackXuXin
Copy link

@JackXuXin update your xcode command line tools

i have updated xcode command line tools

@ankurk91
Copy link
Author

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

@apazadev
Copy link

Very appreciated, thanks!

@Mrjavaci
Copy link

Mrjavaci commented Sep 6, 2021

Thank you

@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