Is their any way to configure xdebug on linux+magento+sublime debug environment ?
I am using PHP Version 7.3.26-1+ubuntu18.04.1+deb.sury.org+1
-
Any thoughts on this ?devhs– devhs2021年03月17日 09:53:08 +00:00Commented Mar 17, 2021 at 9:53
1 Answer 1
Configure Xdebug for Magento 2
I assumed you have already installed below softwares
- Ubuntu 18.04
- PHP 7.4
- Apache/2.4.29
- Sublime Text 4 (Build 4113)
- Magento 2.4.x
Xdebug Installation
- Install xdebug on ubuntu 18.04 LTS, Please use below command
sudo apt-get install php-xdebug
- We need to install a php specific version as well.
sudo apt-get install php7.4-xdebug
Locate xdebug.ini file
First we need to find the xdebug.ini file for both command line php and apache fpm php.
First we will find out xdebug.ini for apache fpm.
Create a new php page add phpinfo() function add open url using browser. We will get the xdebug.ini file path. enter image description here
Apache fpm xdebug.ini file path is
/etc/php/7.4/apache2/conf.d/20-xdebug.ini
- Execute below command it will give xdebug.ini file path for command line php.
php --ini
- Command line php xdebug.ini file path is
/etc/php/7.4/cli/conf.d/20-xdebug.ini
PHP configuration for xdebug
- We need to configure php to use xdebug.
- We need to configure both the php installations command line and apache fpm php.
- Add below line of code in both (cli and fpm) xdebug.ini file, If this code already does not exist.
zend_extension=xdebug
enter image description here enter image description here
- Restart the apache 2 server using command below
sudo service apache2 restart
Verify xdebug installation
On command line we can verify xdebug installation using command line
php -v
On apache2 web server create a php page and below code.
echo xdebug_info();
Xdebug configuration
- We need to configure both the php installations command line and apache fpm php.
- Open xdebug.ini file using below commands
sudo nano /etc/php/7.4/apache2/conf.d/20-xdebug.ini sudo nano /etc/php/7.4/cli/conf.d/20-xdebug.ini
- Add below code in both xdebug.ini files zend_extension=xdebug.so xdebug.client_port=9000
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.idekey=sublime.xdebug
xdebug.client_host=127.0.0.1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
- Restart the apache 2 server sudo apache2 service restart
Sublime Text 4 Configuration
Please make sure you have already installed Package Control. If you not installed package control, Please install this using below link https://packagecontrol.io/installation
Start sublime text editor. Go to "Tools > Command > Palette" search for the install package. enter image description here
Now search for the "Xdebug Client" package and install this package. https://packagecontrol.io/packages/Xdebug%20Client https://github.com/martomo/SublimeTextXdebug
Open sublime project file (projectName.sublime-project) and add below code.
"settings": { "xdebug": { "url": "http://m2p/index.php", "super_globals": true, "close_on_stop": true } }
Here http://m2p/index.php is our magento website link.
Start/Stop the Xdebug session
Now we will start the xdebug session. Go to "Tools > Xdebug > Start Debugging (Launch Browser)"
This will start the xdebug session. This will also open your website home page with "?XDEBUG_SESSION_START=sublime.xdebug" added in the url.
Add Breakpoints
- Open the php file which you want to debug
- Right click on the line where you want to add a breakpoint. Go to the Xdebug menu and click on the Add/Remove breakpoint option.
Load the url http://m2p/test.php using the browser. You will see the code debugger started. enter image description here
Troubleshooting
- After installation of xdebug if you reload the site home page and you get 500 errors. I got this error while configuring xdebug on Magento2.3. If you got this error please use the below solution.
- First check your apache error log file. If your error log file contains errors like below. PHP Fatal error: Uncaught Error: Call to undefined function xdebug_disable()
- Please refer to the solution below to resolve this error. Uncaught Error: Call to undefined function xdebug_disable()
Happy debugging
Thank You