{"id":57924,"date":"2023-08-19T17:50:06","date_gmt":"2023-08-19T12:20:06","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=57924"},"modified":"2023-08-30T17:58:40","modified_gmt":"2023-08-30T12:28:40","slug":"how-to-install-xdebug-3-on-macos","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/how-to-install-xdebug-3-on-macos\/","title":{"rendered":"How to install Xdebug 3 on MacOS"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Xdebug is an extension for PHP, and provides a range of features to improve the PHP development experience. It allows you <em>to break during code execution and inspect all the variables in scope during a request.<\/em><\/span><\/p>\n<p><span style=\"font-weight: 400;\">The purpose of this blog is to install Xdebug 3 on MacOS with PHP 8.1\u00a0 to debug PHP code.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Let\u2019s start installing Xdebug 3 on MacOs:<\/span><\/h2>\n<p><b>Step 1:<\/b><span style=\"font-weight: 400;\"> First check whether PHP 8.1 is installed or not; if not, run the below command:<\/span><\/p>\n<pre><b>brew install php@8.1<\/b><\/pre>\n<p><b>Step 2: <\/b>To <span style=\"font-weight: 400;\">Install Xdebug, run the below command:<\/span><\/p>\n<pre><b>pecl install xdebug<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">If found\u00a0 warning like <\/span><b>\u00a0<\/b><b>PHP Warning:\u00a0 mkdir(): File exists in \/opt\/homebrew\/Cellar\/php\/8.1.8\/share\/php\/pear\/System.php on line 294<\/b><\/p>\n<p><span style=\"font-weight: 400;\">First, create pecl directory by using the command: <\/span><b>mkdir \/opt\/homebrew\/lib\/php\/pecl<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Then again, run the command:<\/span><\/p>\n<pre><b>pecl install xdebug<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">After running the above command, you will see the below output:<\/span><\/p>\n<pre>running: find \"\/private\/tmp\/pear\/temp\/pear-build-rootO1x6b4\/install-xdebug-3.2.2\" | xargs ls -dils\r\n15982931 0 drwxr-xr-x 3 root wheel 96 Aug 9 11:25 \/private\/tmp\/pear\/temp\/pear-build-rootO1x6b4\/install-xdebug-3.2.2\r\n15983635 0 drwxr-xr-x 3 root wheel 96 Aug 9 11:25 \/private\/tmp\/pear\/temp\/pear-build-rootO1x6b4\/install-xdebug-3.2.2\/opt\r\n15983636 0 drwxr-xr-x 3 root wheel 96 Aug 9 11:25 \/private\/tmp\/pear\/temp\/pear-build-rootO1x6b4\/install-xdebug-3.2.2\/opt\/homebrew\r\n15983637 0 drwxr-xr-x 3 root wheel 96 Aug 9 11:25 \/private\/tmp\/pear\/temp\/pear-build-rootO1x6b4\/install-xdebug-3.2.2\/opt\/homebrew\/Cellar\r\n15983638 0 drwxr-xr-x 3 root wheel 96 Aug 9 11:25 \/private\/tmp\/pear\/temp\/pear-build-rootO1x6b4\/install-xdebug-3.2.2\/opt\/homebrew\/Cellar\/php\r\n15983639 0 drwxr-xr-x 3 root wheel 96 Aug 9 11:25 \/private\/tmp\/pear\/temp\/pear-build-rootO1x6b4\/install-xdebug-3.2.2\/opt\/homebrew\/Cellar\/php\/8.1.12\r\n15983640 0 drwxr-xr-x 3 root wheel 96 Aug 9 11:25 \/private\/tmp\/pear\/temp\/pear-build-rootO1x6b4\/install-xdebug-3.2.2\/opt\/homebrew\/Cellar\/php\/8.1.12\/pecl\r\n15983641 0 drwxr-xr-x 3 root wheel 96 Aug 9 11:25 \/private\/tmp\/pear\/temp\/pear-build-rootO1x6b4\/install-xdebug-3.2.2\/opt\/homebrew\/Cellar\/php\/8.1.12\/pecl\/20210902\r\n15983642 776 -rwxr-xr-x 1 root wheel 394950 Aug 9 11:25 \/private\/tmp\/pear\/temp\/pear-build-rootO1x6b4\/install-xdebug-3.2.2\/opt\/homebrew\/Cellar\/php\/8.1.12\/pecl\/20210902\/xdebug.so\r\n\r\nBuild process completed successfully\r\nInstalling '\/opt\/homebrew\/Cellar\/php\/8.1.12\/pecl\/20210902\/xdebug.so'\r\ninstall ok: channel:\/\/pecl.php.net\/xdebug-3.2.2\r\nExtension xdebug enabled in php.ini<\/pre>\n<p><b>Step 3: <\/b><span style=\"font-weight: 400;\">After installing Xdebug<\/span><b>,<\/b> <span style=\"font-weight: 400;\">you must enable this extension in your php.ini file. To enable it, locate the php.ini file location and\u00a0 open php.ini file<\/span><\/p>\n<pre><b>sudo nano \/opt\/homebrew\/etc\/php\/8.1\/php.ini<\/b><\/pre>\n<p><span style=\"font-weight: 400;\">Paste these lines in php.ini file:\u00a0<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">zend_extension=\"xdebug.so\"<\/span>\r\n\r\n<span style=\"font-weight: 400;\">xdebug.mode=debug<\/span>\r\n\r\n<span style=\"font-weight: 400;\">xdebug.start_with_request=yes\r\n\r\n<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Run <\/span><b>sudo apachectl restart<\/b><span style=\"font-weight: 400;\"> command to restart service.<\/span><\/p>\n<p><b>Step 4: <\/b><span style=\"font-weight: 400;\">Now run <\/span><b>php -v <\/b><span style=\"font-weight: 400;\">command to check Xdebug is installed or not:<\/span><\/p>\n<pre>yogendrapratapsingh@Yogendras-MacBook-Pro ~ % php -v\r\nPHP 8.1.12 (cli) (built: Oct 30 2022 12:39:49) (NTS)\r\nCopyright (c) The PHP Group\r\nZend Engine v4.1.12, Copyright (c) Zend Technologies\r\nwith Xdebug v3.2.2, Copyright (c) 2002-2023, by Derick Rethans\r\nwith Zend OPcache v8.1.12, Copyright (c), by Zend Technologies\r\n\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">If found any warning like:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">PHP Warning:\u00a0 Failed loading Zend extension 'xdebug.so' (tried: \/opt\/homebrew\/lib\/php\/pecl\/20210902\/xdebug.so (dlopen(\/opt\/homebrew\/lib\/php\/pecl\/20210902\/xdebug.so, 0x0009): tried: '\/opt\/homebrew\/lib\/php\/pecl\/20210902\/xdebug.so' (no such file)), \/opt\/homebrew\/lib\/php\/pecl\/20210902\/xdebug.so.so (dlopen(\/opt\/homebrew\/lib\/php\/pecl\/20210902\/xdebug.so.so, 0x0009): tried: '\/opt\/homebrew\/lib\/php\/pecl\/20210902\/xdebug.so.so' (no such file))) in Unknown on line 0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Warning: Failed loading Zend extension 'xdebug.so' (tried: \/opt\/homebrew\/lib\/php\/pecl\/20210902\/xdebug.so (dlopen(\/opt\/homebrew\/lib\/php\/pecl\/20210902\/xdebug.so, 0x0009): tried: '\/opt\/homebrew\/lib\/php\/pecl\/20210902\/xdebug.so' (no such file)), \/opt\/homebrew\/lib\/php\/pecl\/20210902\/xdebug.so.so (dlopen(\/opt\/homebrew\/lib\/php\/pecl\/20210902\/xdebug.so.so, 0x0009): tried: '\/opt\/homebrew\/lib\/php\/pecl\/20210902\/xdebug.so.so' (no such file))) in Unknown on line 0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">PHP 8.1.12 (cli) (built: Oct 30 2022 12:39:49) (NTS)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Copyright (c) The PHP Group<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Zend Engine v4.1.12, Copyright (c) Zend Technologies<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0with Zend OPcache v8.1.12, Copyright (c), by Zend Technologies<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Then update <b>zend_extension=&#8221;xdebug.so&#8221; to zend_extension=&#8221;\/opt\/homebrew\/Cellar\/php\/8.1.12\/pecl\/20210902\/xdebug.so\u201d<\/b> in php.ini file. Here updated value will be the same as in Step 2. <\/span><\/p>\n<h2><b>Conclusion<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Finally, <\/span><span style=\"font-weight: 400;\">you\u2019ve successfully installed Xdebug on <\/span><span style=\"font-weight: 400;\">PHP 8.1.<\/span><span style=\"font-weight: 400;\">With Xdebug, you can now debug PHP applications with ease.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let us know in case of any issues during the installation process, and please feel free to reach out via comments.<\/span><\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>Xdebug is an extension for PHP, and provides a range of features to improve the PHP development experience. It allows you to break during code execution and inspect all the variables in scope during a request. The purpose of this blog is to install Xdebug 3 on MacOS with PHP 8.1\u00a0 to debug PHP code. [&hellip;]<\/p>\n","protected":false},"author":1599,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":371},"categories":[3602,1816],"tags":[5324,1701],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57924"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1599"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=57924"}],"version-history":[{"count":3,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57924\/revisions"}],"predecessor-version":[{"id":58210,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57924\/revisions\/58210"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=57924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=57924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=57924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}