visual studio code PHP debugging not working

前端 未结 6 793
清歌不尽
清歌不尽 2021-02-02 13:04

I have installed VS Code and the PHP debugger.

I am using xampp.

I tried running the code (2) ways (listen and launch).

相关标签:
6条回答
  • 2021-02-02 13:21

    Add the following line in your lunch.json file :

    "runtimeExecutable": "c:\\xampp\\php\\php.exe"

    {
        "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,
                "runtimeExecutable": "C:\\Program Files\\PHP\\v7.3\\php.exe"
            }
        ]
    }
    
    0 讨论(0)
  • 2021-02-02 13:24

    For anyone looking answer today, for me helped changing in php.ini section [XDebug] to this:

    xdebug.mode = debug
    xdebug.start_with_request = yes
    zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
    xdebug.stopOnEntry = true
    xdebug.profiler_enable = off
    xdebug.profiler_enable_trigger = Off
    xdebug.profiler_output_name = cachegrind.out.%t.%p
    xdebug.output_dir ="c:\xampp\tmp"
    xdebug.show_local_vars=0
    xdebug.remote_handler = "dbgp"
    xdebug.client_host = "127.0.0.1"
    xdebug.log = "C:\xampp\tmp\xdebug.txt"
    xdebug.client_port = 9000
    xdebug.remote_cookie_expire_time = 36000
    

    I used the settings from post of @Eluny, but with some newer version of the XDebug the properties names changed. On documentation page you can find info about changes

    0 讨论(0)
  • 2021-02-02 13:27

    I’ve restarted everything and still I don’t stop on a breakpoint. Finally, I added this line in php.ini xdebug.remote_port = "9000" Solve my problem.

    0 讨论(0)
  • 2021-02-02 13:32

    Made it just now:

    1. We have OS Windows with Microsoft Visual Code and we have installed 'PHP Debug' module https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug#overview Steps to make it working already wroten here, but I'll write again:

    2. Install XDebug. Online Wizard https://xdebug.org/wizard.php helps you, just post here phpinfo() data. Save in phpinfo.php this:

      <?php phpinfo(); ?>
      

    then open in browser localhost/phpinfo.php, copy everything you see (Ctrl+A then Ctrl+C) to wizard. It shows you obtained info and steps to do:

    1. Open shown in instruction php.ini (there are always many php.ini - apache folder has one php.ini, php has php.ini and phpForApache.ini. But phpinfo makes it clear showing which one is really used)

      2.1. and configure it with xdebug.remote_enable = 1 and xdebug.remote_autostart = 1. My working example:

      [XDebug]
      zend_extension = "c:\wamp64\bin\php\php7.1.9\ext\php_xdebug-2.6.0beta1-7.1-vc14-x86_64.dll"    
      xdebug.stopOnEntry = true
      xdebug.profiler_enable = off
      xdebug.profiler_enable_trigger = Off
      xdebug.profiler_output_name = cachegrind.out.%t.%p
      xdebug.profiler_output_dir ="c:/wamp64/tmp"
      xdebug.show_local_vars=0
      ;xdebug.profiler_output_name = "cachegrind.out.%t-%s"
      xdebug.remote_enable = 1
      xdebug.remote_autostart = 1
      xdebug.remote_handler = "dbgp"
      xdebug.remote_host = "127.0.0.1"
      xdebug.remote_log = "C:\wamp64\tmp\xdebug.txt"
      xdebug.remote_port = 9000
      xdebug.trace_output_dir = "C:\wamp64\tmp"
      xdebug.remote_cookie_expire_time = 36000
      
    2. Restart Apache2 webserver.

    Also:

    For some reason I first got xdebug working on Netbeans for testing, and only then I found option xdebug.remote_autostart = 1 in manual that made it working in VS Code also.

    If you are unsure about XDebug installation, check phpinfo page for "with Xdebug" words and check logs/apache_errors.log for "failed loading php_xdebug" (incorrect DDL downloaded). Then check with any other IDE.

    Good regards!

    0 讨论(0)
  • 2021-02-02 13:34

    I would use NetBeans as they have a more proactive Xdebug interface. Also xdebug V3 has a different port (port 9003) so you should make the adjustments. In netbeans and other debuggers will say port 9000 but its 9003 now

    0 讨论(0)
  • 2021-02-02 13:39

    Have you checked to make sure the firewall allows Inbound connections on Port 9000? I had this exact problem on one of my development machines. While all other settings were correct I wasn't able to hit the break points. Once I added an exception in the firewall it started working.

    So if this is what the issue is with your setting, you have two options to fix it.

    1. Turn OFF your firewall completely, or at least temporarily while you work on your project.
    2. Add an exception to your Firewall settings:
      • Go to your Windows Control Panel and type "Firewall".
      • Select "Inbound Rules" from the left navigation, then click on "New Rule".
      • Select "Port" then hit "Next".
      • Make sure the "Specific local ports" option is selected and type "9000" for the port number.
      • Select "Allow the connection" then hit "Next".
      • Check "Domain", "Private" and "Public" then hit "Next".
      • Enter a descriptive name like "XDebug Port", then hit "Finish".
      • Restart Visual Studio Code, then try debugging again.

    Assuming that you have the Web Server portion of the configuration setup correctly this should allow you to debug.

    Hope this helps.

    0 讨论(0)
提交回复
热议问题