How to setup xdebug for PHP 7 on Mac?

Member

by antone , in category: PHP , a year ago

How to setup xdebug for PHP 7 on Mac?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by hadley , a year ago

@antone 

To set up xdebug for PHP 7 on Mac, you need to perform the following steps:

  1. Install xdebug: Run pecl install xdebug to install xdebug.
  2. Configure xdebug: Add the following lines to your php.ini file:
1
2
3
4
5
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_autostart=1


  1. Restart Apache: Run sudo apachectl restart to restart Apache and apply the changes.
  2. Install an IDE extension: Install an IDE extension for xdebug, such as the one for Visual Studio Code or PHPStorm, to use xdebug.
  3. Debug your code: Start debugging by setting breakpoints in your code and triggering a debugger session from your IDE.


Note: The exact steps may vary based on the version of PHP and the IDE you are using.

by aliyah.nikolaus , 4 months ago

@antone 

Here is a more detailed step-by-step guide on how to set up xdebug for PHP 7 on Mac:

  1. Install xdebug: Open Terminal. Run the following command to install xdebug: pecl install xdebug
  2. Configure xdebug: Open the php.ini file in a text editor. You can find the php.ini file location by running the following command in Terminal: php --ini | grep "Loaded Configuration File" Add the following lines at the end of the php.ini file: zend_extension=xdebug.so xdebug.remote_enable=1 xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000 xdebug.remote_autostart=1
  3. Restart Apache: Run the following command to restart Apache and apply the changes: sudo apachectl restart
  4. Install an IDE extension: Install an extension for your IDE that supports debugging with xdebug. Some popular options include: Visual Studio Code: Install the "PHP Debug" extension by Felix Becker. PHPStorm: Install the "Xdebug Helper" extension by Jetbrains.
  5. Configure the IDE: Open the settings/preferences in your IDE. Configure the xdebug settings to match the following: IDE key: "XDEBUG_ECLIPSE" (for Visual Studio Code) or "PHPSTORM" or "PHP_IDE_CONFIG" (for PHPStorm). Server IP: "127.0.0.1". Port: "9000" (or the port specified in your php.ini file).
  6. Start debugging: Set breakpoints in your PHP code. Start a debugging session in your IDE by either: Triggering a request to your PHP script from a browser with the XDEBUG_SESSION cookie set to the value of your IDE key, or Using the IDE's debug button or menu option.


That's it! You should now be able to debug your PHP code using xdebug on your Mac with PHP 7.