Debug ojs with visual studio code

Hey, I want to debug OJS with visual studio code. So I’d like to start a debugging session in visual studio code which automatically open a URI when debugging. So it should directly open OJS in the localhost. OJS (3.2.0.0) is working fine and I am able to start it with my command line in localhost without any problems.

I tried it with this code in the launch.json but it did not open the index.php in the browser. But the corresponding html is shown in the debug console.

{
“name”: “Launch index.php on port 8000”,
“type”: “php”,
“request”: “launch”,
“program”: “${workspaceFolder}/index.php”,
“args”: [
“-S”, “localhost:8000”
],
“cwd”: “${workspaceFolder}”,
“port”: 9000,
“serverReadyAction”: {
“pattern”: “listening on port ([0-9]+)”,
“uriFormat”: “http://localhost:%s”,
“action”: “openExternally”
}
}

I am looking forward to every answer!

My experience with Visual Studio is unhelpful for this question, but I can share my more general experience with PHP debugging. Perhaps a bit more context will help us help you.

What PHP debugger module do you have installed (Xdebug, DBG)?

Are you using PHP to spin up a built-in server (php -S), or are you running a different server locally (IIS, Apache)?

Hey nevertheless thank you for your answer. I am using Xdebug and I am able to spin up a built-in server exactly like you described.

Of course there is the possibility to set up the config.inc.php by “show_stacktrace = On” so that I can see the errors and warnings direclty in the browser, but I like to start ojs directly in visual studio code.

What options have you used to configure xdebug in php.ini?

I configured the php.ini concerning xdebug with the following abstract:

[xdebug]
zend_extension="/etc/php/7.2/xdebug"
xdebug.remote_enable=1
xdebug.remote_autostart = 1
xdebug.remote_port=“9000”

Seems sane. The xdebug.remote_host default is localhost, so on receipt of a session start command, PHP should reach out to localhost:9000 to presumably find your Visual Studio process listening.

Can you confirm Visual Studio has a listener running with netstat -a | findstr :9000 ?

Can you confirm that Visual Studio is starting the debug session with the PHP built-in server successfully? Is there any visual feedback on session?

Instead of netstat -a | findstr :9000 I used sudo netstat -tulpn | grep LISTEN but I cant find the corresponding listener. Because if I have started the debugging session in visual studio code its directly stopped after a few moments.
The visual feedback that I get is that the main page of visual studio code is outprinted in the debug console. With a few warnings, which are not relevant for this problem, I think.

Are you running Visual Studio on Linux? You’ll want to run this command to look for the listener on port 9000 on the box where Visual Studio is running.