1

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 } ] }
Gama11
  • 31,714
  • 9
  • 78
  • 100
mozpider
  • 366
  • 2
  • 12
  • What's in your xdebug.ini? You can find the location of this file with `php --ini`. – Amade Aug 21 '18 at 14:23
  • Thank you for your response Amade. Added the Xdebug.ini by editing the question – mozpider Aug 21 '18 at 18:16
  • Hmmm, I remember it was tricky to set up, but can't remember the 'catch'. My xdebug.ini (which works) has only `remote_enable`, `remote_autostart`, `remote_port` with the same values as yours, and `zend_extension=xdebug.so`. Can you try to comment out/remove other lines, and run `valet restart`? I am also on Ubuntu 16.04 with valet-linux. – Amade Aug 21 '18 at 20:17
  • one more thing: you're not running it in php's built in server, right? – Amade Aug 21 '18 at 20:21
  • @amade Thank you for inputs. Tried these steps. I am getting http error code 500. I have this index.php in a directory named debug. The directory is parked in valet. I am typing debug.test into the address bar. Before opening in chrome, I am going into the debug mode in VScode, and listening for xdebug. I have also tried typing debug.test:9000 which was not successful either – mozpider Aug 22 '18 at 03:17
  • Just noticed that you're missing a semicolon in `index.php` - can you double check if this is not the issue? – Amade Aug 22 '18 at 11:55
  • I left it on purpose, thinking that the debugger will point me to it. The debugger works when I put the semi-colon back. I thought that the debugger will produce the output "hello" and then get stopped at the break-point which I am setting before the missing semi-colon. Excuse me but I have never debugged php code. I am more used to GDB for C and Fortran. Am I thinking not through ? – mozpider Aug 23 '18 at 00:37
  • 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`. – Amade Aug 23 '18 at 11:16
  • Thank you Amade. You are right. I had wrong expectations. I thought that even in case of C or Fortran, I will not be able to debug, since the code will not compile successfully to produce and debuggable executable. – mozpider Aug 23 '18 at 16:30

1 Answers1

0

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

mozpider
  • 366
  • 2
  • 12