NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Remote CLI SSH debug on Windows server does not from the IDE


Joined: 18 Mar 2019
Posts: 13
Location: Canada
Reply with quote
Hello everybody:

Here is my setup:

Workstation:

    - Windows 11 25H2
    - PhpEd Pro 21.0 (Build 21033)
    - Debug Port 7870

Server:

    - Windows Server 2022
    - Apache 2.4.66 (x64)
    - PHP 8.3.29 (x64_nts)
    - Debug extension v.12.0.23
    - PATH env. variable includes PHP path
    - PHPRC env. variable point to the PHP ini
    - OpenSSH Server (windows)
    - php.ini
    Code:

    zend_extension=dbg-php-8.3.dll
    debugger.enabled=On
    debugger.profiler_enabled=On
    debugger.fail_silently=Off
    debugger.IPv6_enabled=On
    debugger.JIT.enabled=Off
    debugger.hosts_allow=locahost 127.0.0.1 [::1]
    debugger.hosts_deny=ALL
    debugger.ports=7869/10


I can verify that I can SSH and SFTP to the server from the workstation.

I added these items to the IDE accounts:
- SSH terminal
- SSH tunnel
- SFTP file transfer

I verify them that they work independent inside the IDE. I create a project for remote debugging with local files sync with the remote server. Debugging HTTP works without problem. However when I try to debug a CLI, it opens a terminal windows and a pop-up "Waiting for debug session" and writes 12 times on the prompt without executing
Quote:
echo "phped.21.0.0.21033"

ending with one
Quote:
echo $0

Then it timeout and pop another one saying that "Failed to start debug session" and that the debug module is not installed and that I should run the Wizard.

Fine, I deleted the project and ran the wizard. Every prompt goes OK, confirms all the parts of the installation, even it's able to auto upload to the server the dbg-wizard.php. Then Until arrive the part to configure the CLI, when it tries to connect to the terminal get stuck. If I open the details window, I can see the same problem, it keeps writing over and over the
Quote:
echo "php.21.0.0.21033"
. I have to cancel this test and proceed until I complete the project configuration.

Once again, the result is the same HTTP debug, no problem, CLI debug, the same problem as before. Open the terminal writes those 12 echo commands, not execution.

Looking at the documentation of the debugger, it says that the CLI debugger can be manually trigger by putting the DBGSESSID on the environment variables. So from the same prompt that is left without executing, erase all the command and execute this 2 lines.

Code:

set DBGSESSID=1@localhost:7870;d=1
cd C:\my\devapp\folder
php my_cli_script.php


It works without problem. Of course, I could keep doing this, but that is slow, locating the file path on the remote server and execute on the terminal that has the debugging environment. At this point, I would rather to run my own SSH from a Windows Terminal as that is more capable for auto complete, ANSI codes and keys than the terminal build-in the IDE. The only advantage was that you could select the script to debug on the IDE and auto-locate the file and start debugging.

Does anybody has the same problem? Does anybody knows how to fix this? Or should this be considered a bug?

Thanks
View user's profileFind all posts by carloshSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8352
Reply with quote
Thank you for posting this.
Could you check what `echo $0` returns in your terminal? On Linux, it prints the shell type (for example, bash). If you are using bash, it should normally work without issues. However, it's not a Linux environment.

In any case, you can validate your project using the Project Settings Wizard. You can find this button in the Project Properties dialog. The wizard gathers information about PHP and the debugger on your server, then posts a diagnostic log. If it detects any known issues, it may also suggest possible fixes.

You can reply here or in the ticket that you opened with support.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 18 Mar 2019
Posts: 13
Location: Canada
Reply with quote
Hi Dmitri,

Yes, on an SSH Ubuntu, if I type `$echo $0`it will reply `-bash` on Windows SSH replies `$0`.

Maybe if it about how to get information about the shell is running on windows `echo %SHELL%` which will reply `c:\windows\system32\cmd.exe` on Ubuntu `echo $SHELL` reply `/bin/bash`

Do you think it needs to detect the shell that it's running? Do you think it needs a bash shell on windows? I have the Git SCM installed on the server which provides a bash shell. I could try to see if I can change the shell on the Windows OpenSSH server.

However, it will be better if there is a solution without doing these hacks.

I tried to run the wizard settings; all validations pass until arrive to validate the CLI, which does what I described before. If I skip this part and continue, save the project, I can without problem Debug HTTP, but not CLI. On a local installation (of the same projects), I can run the Wizard Settings complete without problems both HTTP and CLI.
View user's profileFind all posts by carloshSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8352
Reply with quote
it needs to detect the shell, otherwise it can’t reliably execute commands or interpret their output. It used to support cmd.exe, but I’m not sure what changed in Windows 22. Can you work with unix-compatible shells under Windows for now? Cygwin or may be similar alternatives. Git comes with a good shell too.
As of the Wizard, don't cancel it, give it at least 30sec

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 18 Mar 2019
Posts: 13
Location: Canada
Reply with quote
I currently I'm trying to change the shell from the OpenSSH server. I will let you know if I can change it and if that helps with the debugger.

When I am run the CLI debugger on the IDE, runs for 30 seconds until show a pop-up that has failed. The SSH terminal shows this:

hxxps://postimg.cc/njyFhLL2

When I run the Wizard, it gets this:

hxxps://postimg.cc/t19D8dNb

Until it fails like this:

hxxps://postimg.cc/sQhBcqGF
View user's profileFind all posts by carloshSend private message


Joined: 18 Mar 2019
Posts: 13
Location: Canada
Reply with quote
Ok I was able to change the Shell from `cmd.exe` to git `bash.exe`. It's a little better, it is able to submit commands but still end up with not debug. No sure why has to submit so many `echo "phped.21.0.0.21033"`. Here is the screenshot of the result.

hxxps://postimg.cc/5Y7NvMm3

Unfortunately, I cannot test if this works on Linux as I have no server with the debugger module installed.
View user's profileFind all posts by carloshSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8352
Reply with quote
Thank you for the update. We need to check how it works internally when running bash / MINGW on Windows.

The repeated echo "phped.21.0.0.21033" appearing on a single line may be related to differences in line endings. Windows does not handle \n correctly on its own and typically expects \r\n.

Previously, we tested only with Cygwin and the native shell. To test compatibility with the native Windows shell, you could try using a Telnet connection instead of SSH. Windows servers come with Telnet service. Telnet client is built-into PhpED. You can give it a try.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 18 Mar 2019
Posts: 13
Location: Canada
Reply with quote
Unfortunately, I will not be able to test it on Telnet as this server is on production and on public network. It will be a "no-no" from our security team. In the past because I couldn't install a reliable and affordable SSH server on windows, we ended installing PhpEd on the server and RDP only for the purpose of debugging. Since Windows 2022, OpenSSH is included on the installation of the OS. I have been installing it for remote debugging HTTP without issue. But until now that I have to debug a CLI script, I am finding this problem.

Now that I know that I can change the sell, I could see if I find a Cygwin bash shell for windows to test with it.

Yes, on the `cmd.exe` shell it makes sense all those echoes are on one line, it output them until times out. But on `bash` shows them on different prompts while executing the same script from 3 to 30 times, depending on the mood. It continues with one `echo $0`, one `env` and it ends with 2 empty prompts. Stays here until times out.
View user's profileFind all posts by carloshSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8352
Reply with quote
For the purposes of PhpED development, we haven’t concidered Windows as a remote platform for PHP cli development, as it’s clearly not very popular in that role. I didn’t realize that, in your case, it is actually used in production. Of course, Telnet is not an option, and, by the way, it hasn’t been included as a Windows component since around Windows 8 or 10. We will improve support for Windows as a remote platform for CLI debugging in the next version.
Cygwin setup is straightforward. Download the Cygwin setup executable, run it, and select the openssh component for installation (it may offer multiple versions, including non-production debug or test builds). After installation, run cygwin.bat, in the the shell execute the ssh-host-setup command. If you don’t enable the isolation option, sshd will work as a service out of the box. With isolation enabled, it may require a few additional tweaks, if I recall correctly.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Site Admin

Joined: 13 Jul 2003
Posts: 8352
Reply with quote
PHP CLI debugging works under Cygwin.
In my setup, all project files are stored remotely on the Windows server.
Project root: [SFTP:win22] /cygdrive/c/Users/Dmitri/Documents/Projects
Run target: remote server
Remote root directory: C:UsersDmitriDocumentsProjects
Terminal account: ssh-terminal-win22
PHP executable: /cygdrive/c/Users/Dmitri/AppData/Roaming/NuSphere/php83/php.exe
Make sure there are no spaces in the path to php.exe

I did not configure SSH port forwarding (tunneling) for debugging because the server is on the same local network.
However, you may need to set up a tunnel if your server is on a different network.

and Windows Firewall should explicitly allow ssh port for external connections. Below is power shell command I used

Code:
New-NetFirewallRule -DisplayName "Cygwin SSHD" -Direction Inbound -LocalPort 22 -Protocol TCP -Action Allow

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Remote CLI SSH debug on Windows server does not from the IDE
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic