3

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

1
  • Any thoughts on this ?
    – devhs
    Commented Mar 17, 2021 at 9:53

1 Answer 1

2

Configure Xdebug for Magento 2

  1. 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
  2. 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

  3. 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

    enter image description here

    • Command line php xdebug.ini file path is

    /etc/php/7.4/cli/conf.d/20-xdebug.ini

  4. 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

  5. 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();

  6. 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
  7. Sublime Text 4 Configuration

    "settings": { "xdebug": { "url": "http://m2p/index.php", "super_globals": true, "close_on_stop": true } }

    Here http://m2p/index.php is our magento website link.

    enter image description here

  8. 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.

    enter image description here

    • 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.

      enter image description here

    • Load the url http://m2p/test.php using the browser. You will see the code debugger started. enter image description here

  9. 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()
  10. Happy debugging

  11. Thank You

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.