How to setup xdebug in Macbook

Are you facing any problems while setting up a local debug environment in Mac?

Shyam Verma
How to setup xdebug in Macbook

Let's get started by doing some code pieces of stuff-

Getting started:

I assume you already have installed PHP.

  1. Open the terminal in your mac (press cmd + space then type terminal and click it to open)

  2. Now navigate to PHP directory:

    cd /usr/local/etc/php
    
  3. Clone the xdebug repository:

    git clone git://github.com/xdebug/xdebug.git
    
  4. Navigate to the repository:

    cd xdebug
    
  5. Type command:

    phpize
    
  6. For configuration Setup type:

    ./configure --enable-xdebug
    
  7. 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

Here, I am using php 7.4, you can use your respective php version's php.ini file.

  • Navigate to PHP 7.4 directory:

    cd /usr/local/etc/php/7.4
    
  • Open php.ini file:

    open -a TextEdit php.ini
    
  • Add these lines at the end of the file:

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

Now, save and close the text editor and type the command:

php -i | grep php.ini

You should see the following output:

Configuration File (php.ini) Path => /usr/local/etc/php/7.4
Loaded Configuration File => /usr/local/etc/php/7.4/php.ini

The Xdebug has been configured.

Now open your VS Code and install xdebug extension (This extension is a debug adapter between VS Code and xDebug) and start debugging your code.

I hope, you have learned how to enable Xdebug and configure it in VSCode for Mac. You can also integrate it in Eclipse, PHPstorm, and other IDEs.

If there is anything you want to know more about, do post your comments and suggestions in the comments section below.

Shyam Verma

Shyam Verma

Full Stack Developer & Founder

Shyam Verma is a seasoned full stack developer and the founder of Ready Bytes Software Labs. With over 13 years of experience in software development, he specializes in building scalable web applications using modern technologies like React, Next.js, Node.js, and cloud platforms. His passion for technology extends beyond coding—he's committed to sharing knowledge through blog posts, mentoring junior developers, and contributing to open-source projects.