Search code examples
phpubuntunginxvisual-studio-codevalet

How to make php-debug extension with Valet on Ubuntu - 502 Bad Gateway


I am debugging a simple index.php with parse errors:

<?php

echo '<h1> Hello </h1>';

$value = 0;

if($value == 0){
    echo "true";
}else{
    echo "false"
}

I have configured the php-debug/Xdebug on my Ubuntu, with the settings read from different forums, but it is not working as I would like it to.

It does not load the local variables, instead opens a server.php.

Chrome shows : 502 Bad Gateway.

Has anybody come across this error?

INSTALLATION DETAILS

OS Description: Ubuntu 16.04.4 LTS Release: 16.04 Codename: xenial

phpinfo() parsed by Xdebug

    Xdebug installed: 2.6.1
Server API: Command Line Interface
Windows: no
Zend Server: no
PHP Version: 7.2.9-1
Zend API nr: 320170718
PHP API nr: 20170718
Debug Build: no
Thread Safe Build: no
Configuration File Path: /etc/php/7.2/cli
Configuration File: /etc/php/7.2/cli/php.ini
Extensions directory: /usr/lib/php/20170718

Valet version 2.0.24 Current Nginx port (HTTP): 80 Current Nginx port (HTTPS): 443## Heading ##

Xdebug.ini

zend_extension=/usr/lib/php/20170718/xdebug.so
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = localhost
xdebug.remote_log = /tmp/xdebug_remote.log
xdebug.remote_mode = req
xdebug.remote_port = 9000 #if you want to change the port you can change

Launch.JSON

{ "version": "0.2.0", "configurations": [ { "name": "Listen for XDebug", "type": "php", "request": "launch", "port": 9000 }, { "name": "Launch currently open script", "type": "php", "request": "launch", "program": "${file}", "cwd": "${fileDirname}", "port":
9000 } ] }

Solution

  • This setup that I have posted for Valet with Xdebug and VScode is correct. It will for your configuration. My expectation about Xdebug to debug a parsing error was not correct. The parse errors should be removed before debugging. The insightful comment from a stackoverflow user Amade is below :

    Okay, in this case, you were doing it right in the beginning, just I think had somehow wrong expectations of xdebug with valet. It will open server.php from valet, since that's where the file with syntax error is required from. I don't think there is anything really you can do about it. But as you're working with VSCode, don't you get notifications of syntax errors in your panel? You can open it with ctrl+j