Xdebug Support: Does DevKinsta Support PHP debugging?

The title says it all. I wonder if PHP debugging is supported?

I don’t know about xdebug, but I think you can log to the error log and check things there. If you’re on Mac, this should be

Users/{yourname}/DevKinsta/logs

Here’s some more info: Logging and Site Debugging - DevKinsta - Kinsta

Thanks @Andre_Gagnon !

@okkins Let us know if you have any trouble finding the logs.

1 Like

Yes, I saw the logs. My question is whether xdebug is enabled in the php build DevKinsta is using? The documentation doesn’t indicate anything about debugging. I’m hoping xdebug is included :slight_smile:

Heey @okkins :smiley: :wave:
xdebug extension is not enabled on the current release of DevKinsta but you can install it using the below commands

docker exec devkinsta_fpm bash -c 'apt-get update;apt-get -y install php7.0-xdebug php7.1-xdebug php7.2-xdebug php7.3-xdebug php7.4-xdebug php8.0-xdebug'
docker restart devkinsta_fpm

Note: Any custom change might be defaulted during containers recycle such as DevKinsta upgrades

3 Likes

Thank you! And do I also need to update the php config or is that handled automatically? I’m not sure where to update php config in docker.

The config files stored inside the containers and are automatically configured but you’re free to edit them as well. You can enter into the container via the following commands:

NGINX:
docker exec -it devkinsta_nginx bash

FPM:
docker exec -it devkinsta_fpm bash

Got it. If the xdebug install configures php correctly that works. I’ll try that and see how it goes. Thanks!

When I run this command I get:
Reading package lists…
Building dependency tree…
Reading state information…
E: Unable to locate package php7.0-xdebug
E: Couldn’t find any package by glob ‘php7.0-xdebug’
E: Couldn’t find any package by regex ‘php7.0-xdebug’
E: Unable to locate package php7.1-xdebug
E: Couldn’t find any package by glob ‘php7.1-xdebug’
E: Couldn’t find any package by regex ‘php7.1-xdebug’
E: Unable to locate package php7.2-xdebug
E: Couldn’t find any package by glob ‘php7.2-xdebug’
E: Couldn’t find any package by regex ‘php7.2-xdebug’
E: Unable to locate package php7.3-xdebug
E: Couldn’t find any package by glob ‘php7.3-xdebug’
E: Couldn’t find any package by regex ‘php7.3-xdebug’
E: Unable to locate package php7.4-xdebug
E: Couldn’t find any package by glob ‘php7.4-xdebug’
E: Couldn’t find any package by regex ‘php7.4-xdebug’
E: Unable to locate package php8.0-xdebug
E: Couldn’t find any package by glob ‘php8.0-xdebug’
E: Couldn’t find any package by regex ‘php8.0-xdebug’

Try running apt-get update && apt-get upgrade first and let us know if this helps.

Yes, that worked and it installed. Now phpinfo() shows xdebug. However, when I started Visual Studio Code with the following config I’m not getting any debugging:

{
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "log": true,
        },
2 Likes

I’m stuck at this point too – my guess is that we need to configure Xdebug remote access so that VS code can bridge into docker but would rather receive instructions from the DevKinsta developers before starting to play with configuration files!

My understanding is that a remote connection is required for xdebug to function with Docker. Let me know if this guide here helps.

I’m not sure how to apply the guide to the docker containers, which PHP configuration files would be applicable and what should the pathMapping values be in the launch json?

What I was hoping for is something similar to the Add-On in local that configures everything:

Hi @michael

I’ve tried following the guide you shared but no joy so far (I’m using Chrome and the Xdebug browser plugin)! This is where I am:

macbookpro ~ % docker exec -it devkinsta_fpm bash

root@2dedc43b17cc:/etc/php/7.4/fpm/conf.d# cat 20-xdebug.ini 
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.remote_host=docker.for.mac.localhost
xdebug.max_nesting_level=1500

macbookpro ~ % exit

macbookpro ~ % docker restart devkinsta_fpm

In visual studio code my launch json is configured as below:

~/DevKinsta/public/greenfins/.vscode/launch.json:

{
    // 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": 9003,
            "pathMappings": {
                "/www/kinsta/public/greenfins": "${workspaceFolder}"
            }
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9003
        }
    ]
}

For good measure I also tried the following because it looks like Xdebug 3 was installed when following the steps from @ramyallam and the guide you shared was for Xdebug 2:

root@2dedc43b17cc:/etc/php/7.4/fpm/conf.d# cat 20-xdebug.ini 
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.idekey=VSCODE
xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal

and…

zend_extension=xdebug.so
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.idekey = VSCODE
xdebug.remote_connect_back = 0
xdebug.remote_host = kubernetes.docker.internal

Still no joy!

I wonder whether Docker needs some more configuration as per https://sebastianhamalainen.com/blog/debug-php-with-vscode-and-docker (add XDEBUG_ENABLE and DOCKERHOST lines under x-environment in docker-compose.yml file). I can’t currently find where DevKinsta stores the compose files, are you able to give me a steer?

Could really do some input from the DevKinsta devs because otherwise I will have to go back to Local (which I really don’t want to do - Kinsta hosting has been flawless so far).

I’m sorry for the trouble here @RWF . We’ll add this as a possible feature of DevKinsta to make this process easier for those using xdebug. I’ll move this thread over to Feature Requests category too and I’ve notified our developers.

1 Like

No worries. Thank you for flagging to the developers – I’m happy to assist with testing (and happy to be contacted directly) if that is helpful to get to the bottom of this. Cheers.

1 Like

Hi @michael, any chance of an update on this? Really need it to move forward with some changes to our Kinsta-hosted site!

Hi @RWF . No updates yet I’m afraid.