PHP / Magento Dev Blog

  • Publikacje
  • O autorze
  • Kontakt

Xdebug – configuration, PHPStorm, debugging Magento plugins

by Henryk Tews / Sunday, 12 August 2018 / Published in Magento 2

Everyone starts with var_dump() and die(). But after a few years working with PHP and Magento 2, those methods start to hurt – especially when debugging a complex order flow with dozens of plugins. I show how to set up Xdebug and why it is worth doing once, properly.

The problem with var_dump in production environments

On large objects (e.g. Magento\Sales\Model\Order) var_dump() dumps tens of thousands of lines that tell you practically nothing. Xdebug solves both problems.

Installing Xdebug 2.x on PHP 7.2

# Check PHP version and architecture
php -v
php -i | grep "PHP Extension Build"

# Install via pecl
pecl install xdebug

# Or via apt (Ubuntu/Debian)
sudo apt-get install php7.2-xdebug

After installation add to php.ini:

[xdebug]
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_autostart=0
xdebug.idekey=PHPSTORM
xdebug.max_nesting_level=512

Note for Magento: set max_nesting_level to at least 512. Magento has deeply nested DI calls and at a lower limit Xdebug will stop the script too early.

PHPStorm configuration

In PHPStorm go to Settings > PHP > Debug and make sure the port is 9000 (Xdebug 2.x) or 9003 (Xdebug 3.x). Then:

  1. Click the phone icon (Start Listening for PHP Debug Connections)
  2. Set a breakpoint in the code (click on a line number)
  3. Call the URL with ?XDEBUG_SESSION_START=PHPSTORM or use the Xdebug Helper browser extension

Practical example – debugging a Magento plugin

<?php

namespace Vendor\Module\Plugin;

use Magento\Catalog\Model\Product;

class PricePlugin
{
    public function afterGetPrice(Product $subject, float $result): float
    {
        // Set a breakpoint here - PHPStorm shows $subject, $result and the full call stack
        $modifiedPrice = $result * 0.9;

        return $modifiedPrice;
    }
}

Summary

Setting up Xdebug takes 15-20 minutes and pays off after the first debugging session on a complex problem. If you work with Magento 2, where a single request can pass through a dozen plugins and interceptors – this is an absolute must-have.

About Henryk Tews

What you can read next

Strategy pattern in PHP – and how Magento 2 uses it in pricing

© 2026 Created by

TOP
Zarządzaj zgodą
Aby zapewnić jak najlepsze wrażenia, korzystamy z technologii, takich jak pliki cookie, do przechowywania i/lub uzyskiwania dostępu do informacji o urządzeniu. Zgoda na te technologie pozwoli nam przetwarzać dane, takie jak zachowanie podczas przeglądania lub unikalne identyfikatory na tej stronie. Brak wyrażenia zgody lub wycofanie zgody może niekorzystnie wpłynąć na niektóre cechy i funkcje.
Funkcjonalne Always active
Przechowywanie lub dostęp do danych technicznych jest ściśle konieczny do uzasadnionego celu umożliwienia korzystania z konkretnej usługi wyraźnie żądanej przez subskrybenta lub użytkownika, lub wyłącznie w celu przeprowadzenia transmisji komunikatu przez sieć łączności elektronicznej.
Preferencje
Przechowywanie lub dostęp techniczny jest niezbędny do uzasadnionego celu przechowywania preferencji, o które nie prosi subskrybent lub użytkownik.
Statystyka
Przechowywanie techniczne lub dostęp, który jest używany wyłącznie do celów statystycznych. Przechowywanie techniczne lub dostęp, który jest używany wyłącznie do anonimowych celów statystycznych. Bez wezwania do sądu, dobrowolnego podporządkowania się dostawcy usług internetowych lub dodatkowych zapisów od strony trzeciej, informacje przechowywane lub pobierane wyłącznie w tym celu zwykle nie mogą być wykorzystywane do identyfikacji użytkownika.
Marketing
Przechowywanie lub dostęp techniczny jest wymagany do tworzenia profili użytkowników w celu wysyłania reklam lub śledzenia użytkownika na stronie internetowej lub na kilku stronach internetowych w podobnych celach marketingowych.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
Zobacz preferencje
  • {title}
  • {title}
  • {title}