How to debug like a pro using Xdebug, PHPStorm, and Docker.

What is XDebug?

Step Debugging

Improvements to PHP’s error reporting

Tracing

Profiling

Code Coverage Analysis

Install and Configure Xdebug

pecl install xdebug; \
docker-php-ext-enable xdebug; \
echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.mode=develop,trace,debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.start_with_request = yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.discover_client_host=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20200930/xdebug.so" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.idekey=PHPSTORM" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \

Setup a server in PHPStorm

  • Click on the PHPStorm icon and select preference.
  • Click on PHP then click on the server
  • Name your server
  • Type localhost as Host
  • Select Xdebug
  • Check path mapping
  • Click ok

Configure Xdebug

  • Click on the PHPStorm icon and select preference.
  • Click on Debug and configure Xdebug
  • Select all the options under Xdebug

Install Browser debugging extensions

Start Listening

Browser debugging extension
place a stopover
Debugger Tab

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Olotin Temitope

Olotin Temitope

287 Followers

Software Developer @andela | Music Lover | Data Science Enthusiast.