XDebug - PHPStorm - Mac: How to configure Xdebug with PHPStorm on Mac OS and PHP 7.3

For this illustration we are using PHP7.3 Find the path of your PHP ini files by opening the console and running following command:
php --ini

In your root folder create a new file using following command and generate Phpinfo file:
sudo vi phpinfo.php

<?php phpinfo(); ?>
view raw phpinfo.php hosted with ❤ by GitHub

Now in your browser run: http://localhost/phpinfo.php . Copy the entire output from this page and paste it into https://xdebug.org/wizard This will give you the download link to xdebug. Now open your console and run below commands:
tar -xvzf xdebug-2.6.0.tgz //Replace with the tar file name which you received from Xdebug wizard
cd xdebug-2.6.0
phpize
| As part of its output it should show:
| Configuring for:
| ...
| Zend Module Api No: 20151012
| Zend Extension Api No: 320151012
./configure
make
cp modules/xdebug.so /usr/local/lib/php/pecl/20170718/
brew services restart php@7.3


Check the path against "Scan the additional .ini files in". In most cases the path would look something like "/usr/local/etc/php/7.3/conf.d"

sudo vi /usr/local/etc/php/7.3/conf.d/ext-xdebug.ini

zend_extension = /usr/local/lib/php/pecl/20180731/xdebug.so #Change this value to your system's Xdebug.so path
xdebug.max_nesting_level = 100000
xdebug.remote_enable = 1
xdebug.remote_port = 9001
xdebug.idekey = PHPSTORM
xdebug.remote_handler = dbgp
xdebug.remote_mode = req
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.remote_timeout = 1000
view raw ext-xdebug.ini hosted with ❤ by GitHub


Now in your PHPStorm perform below steps:
  • Click on PHPStorm > Preferences > Languages & Frameworks > PHP > Debug
  • Under Xdebug > Change "Debug Port" to "9001" and select "Can accept external connections
  • Click on Apply


You can validate your Xdebug installation with PHP using below steps:

You can validate your Xdebug settings for PHPStorm with below steps:
  • Navigate to PHPStorm > Preferences > Languages & Frameworks > PHP > Debug
  • Under Pre-Configuration > Click on Validate debugger configuration on the Web Server
  • Select Local Web Server or Shared Folder
  • Under "Path to create validation script" add path to your Project's Root Directory
  • Under "URL to validation script" add your localhost URL or URL to your project home-page
  • Click on Validate


In order to run Xdebug do following settings in your PHPStorm:
  • Navigate to PHPStorm > Run > Edit Configurations
  • Click on "+" symbol at top left of the window and select "PHP Remote Debug" from the drop-down list
  • In the right-hand pane add the name of your Xdebug profile. For example "My Remote Debug"
  • In the right-hand pane Under configuration tab select "Filter debug connection by IDE Key"
  • Click on "..." near Server and add your project settings (Name: Project Name, Host: Your project's localhost URL - example.local, Port: 80, Debugger: Xdebug) and click on Apply
  • Add "PHPSTORM" against IDE key(sessiod id)
  • Click on Apply
Your Xdebug is now ready to use. Place a breakpoint in your codebase and run the host URL in your browser, it will stop at the breakpoint. Picture Source: pexels.com

Comments

Popular posts from this blog

SEO for your Press Releases [Updated 2025 list]