{"id":1687,"date":"2024-09-11T17:50:02","date_gmt":"2024-09-11T14:50:02","guid":{"rendered":"https:\/\/plumrocket.com\/learn\/?p=1687"},"modified":"2024-10-10T11:05:10","modified_gmt":"2024-10-10T08:05:10","slug":"how-to-configure-xdebug-for-magento-2-application-via-phpstorm-or-vscode","status":"publish","type":"post","link":"https:\/\/plumrocket.com\/learn\/configuring-magento-2-xdebug","title":{"rendered":"How to Configure Xdebug for Magento 2 Application via PHPStorm or VSCode"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full disable_zoom\"><img loading=\"lazy\" width=\"1600\" height=\"600\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration.png\" alt=\"How to Configure Xdebug for Magento 2 Application via PHPStorm or VSCode\" class=\"wp-image-1710\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration.png 1600w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-300x113.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-1024x384.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-768x288.png 768w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-1536x576.png 1536w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-1568x588.png 1568w\" sizes=\"(max-width: 1600px) 100vw, 1600px\" \/><\/figure>\n\n\n\n<p>Finding the cause of errors in heavy frameworks like Magento 2 can take time and effort. Tools like echo, var_dump, and debug_backtrace cannot cover or significantly limit developers&#8217; needs. Xdebug for Magento 2 can successfully address this challenge for developers.<\/p>\n\n\n\n<p>Xdebug is a powerful PHP extension designed specifically to help <a href=\"\/magento-development\" target=\"_blank\" rel=\"noreferrer noopener\">developers<\/a> in debugging. It has a wide range of features that streamline the error-finding process and offer valuable insights. Installing this application can sometimes be tricky, so we prepared a step-by-step tutorial on configuring Xdebug for Magento 2 application via PHPStorm or VSCode.<\/p>\n\n\n\n<h2>Using Xdebug for Magento 2<\/h2>\n\n\n\n<p>Step debugging is a tool that allows you to execute code line by line while monitoring the values of variables and objects. You can also keep track of which specific function is used after a specific line of code is executed, analyze the program execution flow, and much more.<\/p>\n\n\n\n<p>For a step debbugging in php exists an Xdebug extension. It has many features, but the most valuable are step debugging and breakpoints (you can set breakpoints to pause execution at specific points in your code). These and other features are very useful when debugging code and can cover a wide range of developer needs.<\/p>\n\n\n\n<h2>How to Configure Xdebug for Magento 2<\/h2>\n\n\n\n<p>The installation of Xdebug may differ slightly depending on the server&#8217;s operating system. In this tutorial, code examples are written for the Ubuntu operating system.<\/p>\n\n\n\n<h3>Step #1. Install Xdebug<\/h3>\n\n\n\n<p>To install Xdebug, run the following command:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-php\">sudo apt install php8.3-xdebug<\/code><\/pre><\/div>\n\n\n\n<p>If you receive the error <em>Unable to locate package php8.3-xdebug<\/em>, before installing the package you need to add a repository containing the following command:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-php\">sudo add-apt-repository ppa:ondrej\/php\nsudo apt update\n<\/code><\/pre><\/div>\n\n\n\n<p>Now, after checking the PHP version, you can see that the Xdebug extension has been installed:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1159\" height=\"159\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-1-1.png\" alt=\"How to Configure Xdebug for Magento 2: Step 1\" class=\"wp-image-1714\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-1-1.png 1159w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-1-1-300x41.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-1-1-1024x140.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-1-1-768x105.png 768w\" sizes=\"(max-width: 1159px) 100vw, 1159px\" \/><\/figure>\n\n\n\n<h3>Step #2. Configure Xdebug<\/h3>\n\n\n\n<p>To have Magento 2 Xdebug work correctly, you need to make a number of settings, which are specified in the <code>php.ini<\/code> file. Execute the following command to find the path to the file:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-php\">php8.3 \u2013ini<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1159\" height=\"141\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-2-1.png\" alt=\"How to Configure Xdebug for Magento 2: Step 2\" class=\"wp-image-1716\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-2-1.png 1159w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-2-1-300x36.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-2-1-1024x125.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-2-1-768x93.png 768w\" sizes=\"(max-width: 1159px) 100vw, 1159px\" \/><\/figure>\n\n\n\n<p>The following configurations must be added to the end of the <code>php.ini<\/code> file:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-php\">xdebug.mode=debug\nxdebug.trigger_value=runcode\n<\/code><\/pre><\/div>\n\n\n\n<h3>Step #3. Install Browser Extension to Trigger Xdebug<\/h3>\n\n\n\n<p>There are two ways of testing Magento 2 using Xdebug: via VSCode or PHPStorm. Both require the installation of a browser extension to trigger Xdebug. These extensions add cookies to HTTP requests that trigger Xdebug and initiate a debugging session.<\/p>\n\n\n\n<p>You can install these extensions, such as <a href=\"https:\/\/chromewebstore.google.com\/detail\/xdebug-helper\/eadndfjplgieldjbigjakmdgkmoaaaoc\">Xdebug helper<\/a>, through the browser store.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1206\" height=\"385\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-3.png\" alt=\"How to Configure Xdebug for Magento 2: Step 3 \u2014  Xdebug Helper Extension\" class=\"wp-image-1692\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-3.png 1206w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-3-300x96.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-3-1024x327.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-3-768x245.png 768w\" sizes=\"(max-width: 1206px) 100vw, 1206px\" \/><\/figure>\n\n\n\n<p>In the extension configurations, you need to specify the <code>idekey<\/code>, which will match the value <code>xdebug.trigger_value<\/code>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1206\" height=\"453\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-4.png\" alt=\"How to Configure Xdebug for Magento 2: Step 3 \u2014  Extension Configuration\" class=\"wp-image-1693\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-4.png 1206w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-4-300x113.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-4-1024x385.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-4-768x288.png 768w\" sizes=\"(max-width: 1206px) 100vw, 1206px\" \/><\/figure>\n\n\n\n<h3>Step #4. Start Magento 2 Xdebug Testing (VSCode and PhpStorm Explained)<\/h3>\n\n\n\n<p>Once you have installed and configured Xdebug and set up a browser extension to trigger it, you&#8217;re ready to begin testing Magento 2 in either VSCode or PhpStorm. Below, we offer a detailed step-by-step guide to help you through the process.<\/p>\n\n\n\n<h4>Testing Magento 2 with Xdebug in VsCode<\/h4>\n\n\n\n<div class=\"wp-block-group pr-notice pr-notice-info\"><div class=\"wp-block-group__inner-container\">\n<p class=\"pr-notice-title\" style=\"margin-bottom: 25px;\">Step-by-step guide:<\/p>\n\n\n\n<ol><li>Install an extension that allows PHP code debugging. You may use <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=DEVSENSE.phptools-vscode\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">PHP DEVSENSE<\/a> or <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=xdebug.php-debug\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">PHP Debug extensions<\/a>.<\/li><li>If you test Magento 2 in a local environment, you may proceed to launch the debugging process in VSCode. Click Run > Start Debugging (or F5 shortcut) > Listen for Xdebug.<\/li><li>Add a breakpoint on any line that requires debugging. Place the cursor on the left area from the code line number to trigger the red dot (circle) and click on it.<\/li><\/ol>\n<\/div><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1206\" height=\"775\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-5.png\" alt=\"Testing Magento 2 with Xdebug in VsCode\" class=\"wp-image-1696\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-5.png 1206w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-5-300x193.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-5-1024x658.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-5-768x494.png 768w\" sizes=\"(max-width: 1206px) 100vw, 1206px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h4>Testing Magento 2 with Xdebug in PhpStorm<\/h4>\n\n\n\n<div class=\"wp-block-group pr-notice pr-notice-info\"><div class=\"wp-block-group__inner-container\">\n<p class=\"pr-notice-title\" style=\"margin-bottom: 25px;\">Step-by-step guide:<\/p>\n\n\n\n<ol><li>Click Run &gt; Start Listening for PHP Debug Connections.<\/li><li>Set the breakpoint on a line that requires debugging. To do so, navigate the cursor to the line number and click the red dot.<\/li><li>After the first debug launch, PhpStorm will offer to automatically add the server and map the local environment and server files.&nbsp; If the development is carried out in a local environment, it\u2019s enough to click Accept.<\/li><\/ol>\n\n\n\n<p><\/p>\n<\/div><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1206\" height=\"411\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-6.png\" alt=\"Testing Magento 2 with Xdebug in PhpStorm: Step 1-3\" class=\"wp-image-1698\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-6.png 1206w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-6-300x102.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-6-1024x349.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-6-768x262.png 768w\" sizes=\"(max-width: 1206px) 100vw, 1206px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-group pr-notice pr-notice-info\"><div class=\"wp-block-group__inner-container\">\n<ol start=\"4\"><li>After the connection is accepted, the debugging session will start.<\/li><\/ol>\n<\/div><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1206\" height=\"837\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-7.png\" alt=\"Testing Magento 2 with Xdebug in PhpStorm: Step 4\" class=\"wp-image-1699\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-7.png 1206w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-7-300x208.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-7-1024x711.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration-7-768x533.png 768w\" sizes=\"(max-width: 1206px) 100vw, 1206px\" \/><\/figure>\n\n\n\n<p>We hope you found this article useful. If you have any difficulties, we are happy to help you with our\u00a0<a href=\"\/magento-development\" target=\"_blank\" rel=\"noreferrer noopener\">Magento development services<\/a>. Please comment and share. Thanks for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Xdebug is a powerful PHP extension designed specifically to help developers in debugging. It has a wide range of features that streamline the error-finding process and offer valuable insights. Installing this application can sometimes be tricky, so we prepared a step-by-step tutorial on configuring Xdebug for Magento 2 application via PHPStorm or VSCode.<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[144,163],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to configure Magento 2 Xdebug via PHPStorm &amp; VSCode<\/title>\n<meta name=\"description\" content=\"A step-by-step guide on configuring Xdebug for Magento 2 via PHPStorm or VSCode. Debug complex projects for efficient work.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/plumrocket.com\/learn\/configuring-magento-2-xdebug\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to configure Magento 2 Xdebug via PHPStorm &amp; VSCode\" \/>\n<meta property=\"og:description\" content=\"A step-by-step guide on configuring Xdebug for Magento 2 via PHPStorm or VSCode. Debug complex projects for efficient work.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/plumrocket.com\/learn\/configuring-magento-2-xdebug\" \/>\n<meta property=\"og:site_name\" content=\"Magento Tutorials for Beginners &amp; Professionals\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-11T14:50:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-10T08:05:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/09\/magento-xdebug-configuration.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/posts\/1687"}],"collection":[{"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/comments?post=1687"}],"version-history":[{"count":15,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/posts\/1687\/revisions"}],"predecessor-version":[{"id":1940,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/posts\/1687\/revisions\/1940"}],"wp:attachment":[{"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/media?parent=1687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/categories?post=1687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/tags?post=1687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}