How install Xdebug on MacOS

How install Xdebug on MacOS

How install Xdebug on MacOS

.

What is XDebug?

While PHP does not come with a full toolkit for debugging and profiling, an open-source project has existed almost as long as PHP to provide both: Xdebug. Created and maintained by PHP core developer Derick Rethans, it offers remote debugging, stack traces, profiling, and more. It is a project that anyone doing PHP development would benefit from using.

Install XDebug on MacOS

Download and build XDebug

First install PHP on your machine

  • Open the terminal in your mac (press cmd + space then type terminal and click it to open)
  • Now : cd /usr/local/etc/php
  • Clone the xdebug repository: git clone git://github.com/xdebug/xdebug.git
  • Navigate to the repository: cd xdebug
  • Type command: phpize
  • For configuration Setup type: ./configure --enable-xdebug
  • Now, build an executable program from your source code by running the command: sudo make && sudo make install

The package is now installed and located at :
/usr/local/etc/php/xdebug/modules/xdebug.so

The package is now ready to use but we need to do a few more configurations in the php.ini file but first check your path of the file named xdebug.so ( it will be at your zend_Extension path )

cd /usr/local/lib/php/pecl

Here you can see a few folders, find the folder which contains the xdebug.so file.
In my case xdebug.so file path is:
/usr/local/lib/php/pecl/20190902/xdebug.so

Install XDebug

go to php.ini folder and add this config to it:

   
        zend_extension = /usr/local/lib/php/pecl/20190902/xdebug.so
        xdebug.mode = debug
        xdebug.start_with_request = yes
        xdebug.client_port = 9000