Debugging Kirby sites and PHP in ST3

What do you use, on ST3, to debug Kirby sites and PHP in general?

dump() is usually fine to debug in templates and snippets, but, say, routes? a pain… I also miss breakpoints.

Thank you

I don’t use ST3, but how about good ol’ Xdebug?

Hello, thanks

I am trying to set Xdebug on ST3 without luck for now.

If someone has done it, any help would be appreciated.

Any alternative would be also great,

Thank you

What issues did you run into?

You might also want to look into Ray app by Spatie (but it requires you to write debugging code in your code instead of using breakpoints and needs a license). So it’s more var_dump on steroids:

I am unsure of the issue, but it may be related to plugin configuration.

The following is xdebug config at /etc/php/7.4/cli/conf.d/20-xdebug.ini

zend_extension=xdebug.so
xdebug.remote_enable = 1
xdebug.remote_host = "127.0.0.1"
xdebug.remote_port = 9003
xdebug.remote_handler = "dbgp"
xdebug.remote_mode = req
xdebug.remote_connect_back = 1
xdebug.remote_log="/var/log/xdebug/xdebug.log"

In ST3 I am using the plugin GitHub - martomo/SublimeTextXdebug: Xdebug debugger client for Sublime Text 2 and 3 …with default config except for the url setting which I set to the project root, using ST project file. For example for a test project ‘xdebugtest’ with a single index.php file this is my xdebugtest.sublime-project

{
	"folders":
	[
		{
			"path": "."
		}
	],
	"settings":
	{
			"xdebug": {
					"url": "http://localhost/~jaume/dev/xdebugtest/",
			}
	}
}

And this is my index.php

<?php
$a = 1;
$b = 2;
echo $a + $b;

I placed a breakpoint on line 2. When I start debugging the browser opens with the working page, but nothing is shown on context, watch, stack… panels. The page echoes the sum and that’s it.

Thanks for any help you can provide.

Did you also configure it with use of your webserver? What does phpinfo() tell you, if called via webserver? It should contain information about Xdebug.

Looks like you are using Xdebug 2.x and the Github page you are refering to might be outdated.

Setting up Xdebug 3.x together with VSCode following the recipe cited by texnixe works like a charm.

Thanks, @Adspectus .

I am definitively running Xdebug 2.9.2. which is the latest version available on Linux Mint Repos so it seems. And phpinfo shows all of its config.

I gave up on ST3 for now and I am trying to follow @texnixe instructions to get xdebug working on VSCode. No luck for now.

  • This is my xdebug 2.9.2 config as suggested on the recipe (note no IDE key is provided in this snippet, and port is 9000 not 9003):
    zend_extension=xdebug.so
    debug.remote_enable=true
    xdebug.remote_host=localhost
    xdebug.remote_port = 9000
    xdebug.remote_handler=dbgp
    xdebug.remote_autostart = 1

… I restarted apache after saving the config and phpinfo shows me the changes all right.

  • I installed PHP Debug plugin for VSCode.
  • Opened an index.php file with:
<?php
$a = 1;
$b = 2;
echo $a + $b;  

… and added some breakpoints:
image

  • Created a PHP launch.json file as suggested (port is 9000 to match xdebug 2 suggested port):

image

{
    // 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": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000
        }
    ]
}
  • Went to run tab, and clicked on ‘the green triangle’ to initiate ‘Listen for XDebug’ , session is active.
  • Visited my index.php file on chrome, at http://localhost/~jaume/dev/xdebugtest/, the code runs, prints, and nothing is shown on VSCode

What may I be missing?

Thanks again

This is PhpInfo on xdebug options, if it may be of help. Thank you

Directive Local Value Master Value
xdebug.auto_trace Off Off
xdebug.cli_color 0 0
xdebug.collect_assignments Off Off
xdebug.collect_includes On On
xdebug.collect_params 0 0
xdebug.collect_return Off Off
xdebug.collect_vars Off Off
xdebug.coverage_enable On On
xdebug.default_enable On On
xdebug.dump.COOKIE no value no value
xdebug.dump.ENV no value no value
xdebug.dump.FILES no value no value
xdebug.dump.GET no value no value
xdebug.dump.POST no value no value
xdebug.dump.REQUEST no value no value
xdebug.dump.SERVER no value no value
xdebug.dump.SESSION no value no value
xdebug.dump_globals On On
xdebug.dump_once On On
xdebug.dump_undefined Off Off
xdebug.file_link_format no value no value
xdebug.filename_format no value no value
xdebug.force_display_errors Off Off
xdebug.force_error_reporting 0 0
xdebug.gc_stats_enable Off Off
xdebug.gc_stats_output_dir /tmp /tmp
xdebug.gc_stats_output_name gcstats.%p gcstats.%p
xdebug.halt_level 0 0
xdebug.idekey no value no value
xdebug.max_nesting_level 256 256
xdebug.max_stack_frames -1 -1
xdebug.overload_var_dump 2 2
xdebug.profiler_append Off Off
xdebug.profiler_enable Off Off
xdebug.profiler_enable_trigger Off Off
xdebug.profiler_enable_trigger_value no value no value
xdebug.profiler_output_dir /tmp /tmp
xdebug.profiler_output_name cachegrind.out.%p cachegrind.out.%p
xdebug.remote_addr_header no value no value
xdebug.remote_autostart On On
xdebug.remote_connect_back Off Off
xdebug.remote_cookie_expire_time 3600 3600
xdebug.remote_enable Off Off
xdebug.remote_host localhost localhost
xdebug.remote_log no value no value
xdebug.remote_log_level 7 7
xdebug.remote_mode req req
xdebug.remote_port 9000 9000
xdebug.remote_timeout 200 200
xdebug.scream Off Off
xdebug.show_error_trace Off Off
xdebug.show_exception_trace Off Off
xdebug.show_local_vars Off Off
xdebug.show_mem_delta Off Off
xdebug.trace_enable_trigger Off Off
xdebug.trace_enable_trigger_value no value no value
xdebug.trace_format 0 0
xdebug.trace_options 0 0
xdebug.trace_output_dir /tmp /tmp
xdebug.trace_output_name trace.%c trace.%c
xdebug.var_display_max_children 128 128
xdebug.var_display_max_data 512 512
xdebug.var_display_max_depth 3 3

And phpinfo() shows definitely PHP version 7.4?

Hello, thank you, 7.4.3 yes.

Also, @pixelijn :

jaume@xochiquetzal ~ $ php -v
PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
    with Xdebug v2.9.2, Copyright (c) 2002-2020, by Derick Rethans

Thanks, @plagasul. But the PHP version shown in the CLI might differ from the one actually used by your server.

Yes, I meant both phpinfo() and php -v show PHP 7.4.3 with Xdebug v2.9.2

Thanks for helping

Your screenshot does not reveal your script where you have set the breakpoint - but I am sure you did, didn’t you?

Once you have started Xdebug in VS Code, can you see it is running and listening on the dedicated host and port? I.e., does netstat -ltpn run as root show you something like this:

tcp6    0   0 :::9000           :::*              LISTEN      12345/code

or

tcp     0   0 0.0.0.0:9000      0.0.0.0:*         LISTEN      12345/code

Yes, I see the line. I actually see three that belong to CODE:

tcp        0      0 127.0.0.1:40409         0.0.0.0:*               ESCUCHAR    183506/code
tcp6       0      0 :::38439                :::*                    ESCUCHAR    183506/code         
tcp6       0      0 :::9000                 :::*                    ESCUCHAR    200675/code     

…and there is nothing else on port 9000 btw

Weired. One other try:

Shouldn’t this read xdebug.remote_enable?

It is going to be one little silly thing I am sure…

Thank you all very much for helping, it is always frustrating to encounter this blockades.

And by the way you are correct, xdebug.remote_enable is OFF, and this seems the result of a copy paste error, let me give it a try…

…aand it works…

as said… one little silly thing in the ocean of effort.

Again, thank you very much all of you, and thanks @Adspectus for noticing that mistake.

I will leave this open and, armed with the gained knowledge about Xdebug options, will attempt to reinstall in ST3 and post results here. Perhaps even a recipe? that’d be nice.

Danke schön

Thanks a lot for bringing up this subject. I was looking into getting XDebug to run in ST3 a while ago and I gave up on it, because it seemed too complicated. Will later have a closer look at this thread and give it another try. Much appreciated.