Login Contact Us
My cart

Installing Xdebug 3 on PHP 8.1 Ubuntu 20.4 and using it with Magento 2.4

Jul 9, 2023
by Mexbs Team
Magento Tutorials

Magento 2.4.4 versions and higher require PHP 8.1, so it is handy to have Xdebug installed. In this article, we will show the simple steps to install Xdebug for PHP 8.1 on Ubuntu 20.4 with PHPstorm.

First, update apt and install Xdebug:

You should get a message similar to this:

Afterwards, go to the PHP directory and create the xdebug configuration file:

Paste the following lines into the 20-xdebug.ini file: Note that the zend_extension parameter is taken from the CLI output above. Also note that the Xdebug version that is compatible with PHP 8.1 is Xdebug 3, and it has some differences in configurations from Xdebug 2. (For example client_host instead of remote_host)

Also, note that I am using the IP of my computer as a host (my Magento site is running on Virtual Box), and I use port 9001 in my PHPstorm:

Now, create symlinks for Apache and CLI to the Xdebug config file, and restart apache

Now, run the php -v command to make sure that the Xdebug is installed properly. You should see something like that:

Now, make sure that the debugger listener is on in the PHPStrom:

And try going to your website with the parameter ?XDEBUG_SESSION_START=123456 appended to the URL, it should prompt the debugger in PHPStorm.

If you want to debug CLI code, run the following command to set the environment variable first:

Note that these parameters match the following server configuration in PHPstorm:

Now run any Magento command in the CLI, and it should prompt the debugger in PHPstorm