Search code examples
linuxubuntuserverphpstormxdebug

PhpStorm remote Xdebug


I've got problems with setting up Remote Web Server Debugging with Xdebug. I keep getting 404 error:

enter image description here

but actually Xdebug is being detected correctly:

enter image description here

How are machines setup

  • Laptop and Desktop PC are connected in the same network
  • Laptop has Ubuntu 18 installed and I'm using it as server
  • There is a Docker on laptop with file sync but this doesn't matter at this point
  • PhpStorm is on my Desktop PC,
  • Vsftpd is configured correctly, files edited on Desktop are being sent on laptop and page data is being update in container,
  • my website works locally at 192.168.1.103

What works fine at this point

  • FTP connection with laptop,
  • SFTP connection with laptop,
  • SSL,
  • SSH connection from desktop via for example Git Bash,
  • Xdebug itself works fine on laptop.

What I already tried


    zend_extension=/usr/lib/php/20170718/xdebug.so
    xdebug.remote_autostart = 1
    xdebug.remote_enable = 1
    xdebug.remote_handler = dbgp
    xdebug.remote_host = 127.0.0.1
    xdebug.remote_log = /tmp/xdebug_remote.log
    xdebug.remote_mode = req
    xdebug.remote_port = 9005

  • I've tried with changed remote host to the IP on which website works, didn't helped.
  • Also Apache DocumentRoot was setup on /var/www while my project was somewhere else so I move project to /var/www and still nothing - but works OK on given IP above.

I'm out of ideas at this point.

P.S. I'm newbie to Linux.


Solution

  • First of all I’m unable to pinpoint what was exactly the problem, however I’ve got few ideas looking on what I’ve changed and it suddenly started to work.

    Step by step what I’ve made in order to make connection work this time.

    1. Creating new remote project
    2. Defining connection with FTP (in my case I’m connecting to my laptop with Ubuntu)

    enter image description here

    At this point the difference is that:

    • I’ve pointed the location manually
    • I’ve changed the Web server root URL, previously it was just IP without port etc

    Next thing is Mapping. Once I’ve setup correct path in Connection tab all I had to do is:

    enter image description here

    1. Selecting CLI and Path mapping

    Once the connection is established, There will be list of detected remote CLI Interpreters. I’ve picked up my Laptop’s Ubuntu. Again keep an eye on Path mappings, it should be the same Root Path above.

    enter image description here

    Now once You press the marked button in CLI line, You will see new windows. In my case xdebug was detected.

    enter image description here

    Press „Open in Editor”

    1. Xdebug settings

    Below are the settings I’ve got in php.ini:

    zend_extension = /usr/lib/php/20170718/xdebug.so
    xdebug.remote_autostart = 1
    xdebug.remote_enable = 1
    xdebug.remote_handler = dbgp
    xdebug.remote_connect_back = 1
    xdebug.remote_host = "192.168.1.100" //This is my Desktop PC IP
    xdebug.remote_log = /tmp/xdebug_remote.log
    xdebug.remote_mode = req
    xdebug.remote_port = 9101 //This is the port under which I want xdebug to work remotely
    xdebug.idekey = "PHPSTORM"
    

    Below are settings for my Xdebug.ini file on Ubuntu (the same as above):

    enter image description here

    It’s worth mentioning that I had 127.0.0.1 as remote_host and Validation tool actually detected my Desktop IP this time.

    1. Validating Xdebug connection enter image description here

    Keep an eye on underlined sections – this are my settings. Now go to Validate.

    Upon pressing Validate, You should see settings like these below. Again be sure to pick up proper Remote connection.

    enter image description here

    The rest goes just with the official guide – setup Xdebug extension in browser and start listening for incoming connections.

    Below are some useful links that might be helpful in case You will have some other kind of problems.