XDebug is a popular code debugging tool for PHP that seamlessly integrates with PHPStorm IDE. In this guide, we will walk you through the steps to set up XDebug on your Linux development machines.
Please follow the below steps:
Step 1: Install XDebug 3
Reference: https://xdebug.org/docs/install#linux
Assuming the currently installed PHP version is 7.4.
Run below command to install xdebug:
1 |
sudo apt-get install php-xdebug |
Step 2: Configure php.ini
Reference: https://xdebug.org/docs/install#configure-php
Configure the XDebug module in the php.ini file to load and enable it.
Run below command to get the path of xdebug.so file:
>locate xdebug.so
Open php.ini using sudo gedit /etc/php/7.4/apache2/php.ini and paste the code below at the end of the file.
1 2 3 4 5 6 7 8 |
[xdebug] ; specify the exact path to the module file based on the information you receive after the installation. zend_extension="/usr/lib/php/20220829/xdebug.so" xdebug.mode=debug xdebug.client_host=127.0.0.1 xdebug.client_port=9003 xdebug.idekey="PHPSTORM" |
Now, need to restart the apache server. To restart the Apache web server, execute the following command in your terminal:
1 |
sudo systemctl restart apache2 |
Step 3: Verify
Verify Xdebug installation by doing any of the following:
- In the command line, run the following command:
> php –version
Step 3.1
Typically you can create a new 99-xdebug.ini file inside the /etc/php/7.4/cli/conf.d/ directory, if it doesn’t exist already, which will get loaded automatically by the main php.ini file.
After the configuration, restart the PHP service.
1 2 3 4 |
> service php7.4-fpm restart OR > systemctl restart php7.4-fpm.service |
Step 3.2 Create a php file containing the following code:
1 2 3 |
<?php phpinfo(); ?> |
Step 4: Configure PHPStorm
4.1: PHPStorm Project Server
Configure the server path for the project so that PHPStorm knows which
files to listen to.
4.2 PHP CLI Interpreter
Configure the correct PHP interpreter for your project and make sure
PHPStorm can identify your XDebug configuration.
4.3: Configure Debug Tool
Configure the correct debug tool that you want to use with your IDE. In
our case, that would be XDdebug.
4.4 Start Listening
When you are ready to start the debugging, make sure that you have
turned the switch to listen to the XDebug requests to your IDE.
Listen Status: off
Listen Status: on
Reference: https://www.jetbrains.com/help/phpstorm/2021.2/configuringxdebug.html
Now you should be able to add the breakpoints to your PHP code, wherever
necessary, in your IDE and start your debugging process in an efficient way with the
help of Xdebug Helper chrome extension.
Happy Coding!!
bluethinkinc_blog
2023-10-06