How to debug PHP code using xdebug in Atom

First of all, we assume an apache server with php > 7.0 is installed. If not, LAMP. is highly recommended from Bitnami.

  1. Install xdebug.

    xdebug comes with LAMP as an extension, no installation required. If not, for most Linux system, xdebug can be installed using the package management, e.g. apt-get install php-xdebug in Ubuntu

  2. Configure php.ini

    • Append the following text to php.ini
       ;[XDebug]
       zend_extension="where_is_your_xdebug.so"
       xdebug.remote_enable=true
       xdebug.remote_host=127.0.0.1
       xdebug.remote_port=9000
       xdebug.remote_handler=dbgp
       xdebug.profiler_enable=1
       xdebug.profiler_output_dir=/tmp
       xdebug.remote_mode=req
       xdebug.remote_autostart=true
       xdebug.idekey=xdebug-atom
      
    • In LAMP, just uncomment those lines in php.ini and add extra lines as needed.
    • Test whether xdebug is working or not
      • Don’t forget to restart apache server
      • Create a new file under apache htdocs
      • Write <?php phpinfo(); ?> and save it
      • Load webpage in browser and you should see Xdebug enabled in zend engine section
  3. Install Atom and additional packages

    • Install Atom editor and click install under settings
    • Search and install php-debug, atom-debug-ui, ide-php
    • NEVER install atom-ide-ui when prompt (conflicting with php-debug, took me hours to figure this out)
    • Set a breakpoint in Atom and reload the page in browser, you should see the page loading paused and the line where the code stopped is highlighted