Skip to content

Instantly share code, notes, and snippets.

@reetp
Last active December 21, 2021 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reetp/0cc0f2ec73603d57688789a0c59fc201 to your computer and use it in GitHub Desktop.
Save reetp/0cc0f2ec73603d57688789a0c59fc201 to your computer and use it in GitHub Desktop.
Codium/Visual Studio remote debug proxy detup

PHP Remote Debug Proxy setup

Installation

Install extension

You need to install the PHP Debug Extension in Visual Studio /Codium.

You can get all the relevant settings from here:

https://github.com/xdebug/vscode-php-debug

My test server is on 192.168.10.1

Install web server xdebug extension

Make sure you have xdebug installed and loaded on your webserver first. Set these in your php.ini file.

[Debugger]
xdebug.remote_enable                   = true
xdebug.remote_host                     = 127.0.0.1
; Think this is required
xdebug.remote_mode                     = req
; Check the defaults
;xdebug.remote_port                     = 9000
; not sure if this wil log - probably but I don't use it
;xdebug.remote_log                      = /var/log/xdebug.log

Install your debug proxy client

Get a remote debug proxy - this is the Active state version that I am using. I think it is bundled here:

https://www.activestate.com/products/komodo-ide/download-ide/

Or just the Debug package here:

https://code.activestate.com/komodo/remotedebugging/

Setup Visual Studio/ Codium

Here is the debug setup that I am using in Codium. Go to Run and Debug and set this up as launch.json

Name can be any name for your config. Key is your key that you register with.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "vscphpdebug",
            "type": "php",
            "request": "launch",
            "stopOnEntry": true,
            "proxy": {
                "enable": true,
                "host": "192.168.10.1",
                "port": 9001,
                "key": "myvsc",
                "allowMultipleSessions": true
            },
            "pathMappings": {
                "/remote/server/directory": "${workspaceFolder}"
            },
        },
    ]
}

Save the JSON file.

Run the debug proxy on the server

Next run your debug proxy on your webserver

#!/bin/sh
python /root/dbgp/bin/pydbgpproxy -d 127.0.0.1:9000 -i 192.168.10.1:9001 -l DEBUG

Connect the client to the server

Now in VS/Codium you can see a green run button next to "vscphpdebug". Click it or press F5 and it will connect to the server - you should get a registration message

Registering myvsc on port 9003 with proxy @ 192.168.10.1:9001

Registration successful

Start debugging

Now run your code from Firefox - no extensions required

https://192.168.10.1/zTest.php?XDEBUG_SESSION_START=myvsc

Or alternatively from the server command line:

php -f ./zTest.php?XDEBUG_SESSION_START=myvsc

Other users

Another user can use their own key and connect their own instance to the same webserver. Just use a different user key in the launch.json

Stop the connection

To stop the connection use Shift + F5

Tips

If you are debugging a API file to a website you can add the XDEBUG part to a call and that will then trigger debugging on the web app as well eg:

$curl      = new Curl();
$url = "https://192.168.10.1/webapp/index.php?XDEBUG_SESSION_START=users";

$post_data = array(
  'username' => 'admin',
  'password' => 'password'
  'data' = > 'some data'
  );
  
$curl->post($url, $post_data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment