4

I'm using PHP 7.3.1 with Laravel 5.7.

How can I proceed to debug step by step without install a external server? Using Xdebug?

Just running with the command:

php artisan serve

All solution then I founded use WAMP.

4 Answers 4

4

Setup xdebug extension in php.ini file as per your PHP version.

Check which version of xdebug support your PHP here : https://xdebug.org/wizard.php

Don't forget to change your xdebug extension path zend_extension.

Add xdebug extension into the browser also. For mozila click here.

[xdebug]
zend_extension = "C:\php\ext\php_xdebug-2.7.0-7.2-vc15.dll"
xdebug.remote_autostart = 1
;xdebug.profiler_append = 0
;xdebug.profiler_enable = 0
;xdebug.profiler_enable_trigger = 0
;xdebug.profiler_output_dir = "c:\xampp\tmp"
;xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_enable = 1
;xdebug.remote_handler = "dbgp"
;xdebug.remote_host = "127.0.0.1"
;xdebug.remote_log = "c:\xampp\tmp\xdebug.txt"
;xdebug.remote_port = 9000
;xdebug.trace_output_dir = "c:\xampp\tmp"
;36000 = 10h
;xdebug.remote_cookie_expire_time = 36000
;xdebug.trace_output_dir = "C:\xampp\tmp"
Sign up to request clarification or add additional context in comments.

2 Comments

where can I find php.ini if i'm using laravel? i'm not install php. i'm just install laravel project from console with the command "laravel new my-web-site"
You can find php.ini file where you've installed PHP. If you are using windows then check into the C:/PHP or C:/Program Files Check this link : php.net/manual/en/configuration.file.php
2

I'd try starting artisan with Xdebug like php -z /path/to/xdebug.so artisan serve.

And then use the PHP debug extension for Visual Studio code, to set breakpoints, inspect variables and all other debugging stuff.

2 Comments

where can i find xdebug.so? on the website just have xdebug.dll
Oh, you're using Windows! Then it should be xdebug.dll instead. You can ahead and try to use that.
2

Creating a launch.json file within the .vscode directory of the project with the following contents did the trick for me:

{
     // Use IntelliSense to learn about possible attributes.
     // Hover to view descriptions of existing attributes.
     // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
     "version": "0.2.0",
     "configurations": [
         {
             "name": "Listen for XDebug",
             "type": "php",
             "request": "launch",
             "port": 9000
         }

     ]
}

Comments

0

Finished setting up development environment, and would like to list some notes:

  • using Homestead/Vagrant/VirtualBox virtual environment and VSCode PHP Debug plugin

  • edit .vscode/launch.json, or after first F5 will be created with settings like here:

    
       //file: .vscode/launch.json
       "version": "0.2.0",
       "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003
        },
       // ...
    
    
    
  •  # sudo vim /etc/php/8.1/fpm/conf.d/20-xdebug.ini # symlink
     # or sudo vim /etc/php/8.1/mods-available/xdebug.ini
     zend_extension=xdebug.so
     xdebug.mode = debug
     xdebug.discover_client_host = true
     xdebug.client_port = 9003
     xdebug.max_nesting_level = 512
     xdebug.idekey = VSCODE
     xdebug.start_with_request=yes
     xdebug.client_host=10.0.2.15 # <--- my Homestead/Vagrant/VirtualBox IP address (ip addr show)
    
  • sudo service php8.1-fpm restart

  • php artisan serve - will deploy/publish/attach php code to php8.1-fpm service

  • enter image description here

Notes about development environment

  • Host OS is Ubuntu 21.10
  • Have installed VirtualBox and Vagrant
  • Homestead cloned and started - vagrant up
  • vagrant ssh-config copy paste to ~/.ssh/config
  • VSCode extensions
    • Remote - SSH
    • Remote - SSH: Editing Configuration Files
  • Using VSCode extension Laravel Extension Pack collection

Additional notes:

  • there are two parts of Laravel/PHP that could be debugged:
  • php artisan serve - running from shell to deploy/publish/attach php files to php8.1-fpm
    • one way to debug that launching part is to use this command line:
      php \            
        -dzend_extension=xdebug.so \
        -dxdebug.mode=debug \
        -dxdebug.discover_client_host=true \
        -dxdebug.client_port=9003 \
        -dxdebug.max_nesting_level=512 \
        -dxdebug.idekey=VSCODE \
        -dxdebug.start_with_request=yes \
        -dxdebug.client_host=10.0.2.15 \
        artisan serve
      
    • place brake-point somewhere at artisan script in root folder
    • do not need that part at all (just mentioning here for sake of completeness) and could be replaced with php artisan serve
  • service php8.1-fpm status - running in background
    • to debug that part, /etc/php/8.1/mods-available/xdebug.ini file should be configured like here:
      zend_extension=xdebug.so
      xdebug.mode = debug
      xdebug.discover_client_host = true
      xdebug.client_port = 9003
      xdebug.max_nesting_level = 512
      xdebug.idekey = VSCODE
      xdebug.start_with_request=yes
      xdebug.client_host=10.0.2.15
      
    • always do sudo service php8.1-fpm restart after changing /etc/php/8.1/mods-available/xdebug.ini
    • place brake-point somewhere in SomeCustomController.php file
  • keep running IDE debugger (client) with F5 from ./vscode/launch.json and php parts from above will be able communicate with it over port 9003
  • Laravel docs:

    ... consider using Laravel Homestead

  • Xdebug docs:

    There could be more than one php.ini file. In many set-ups there is a different one for the command line (often cli/php.ini) and the web server (often fpm/php.ini)

Helper commands to check if Xdebug extensions are set:

  • php-fpm8.1 -m - Xdebug should be listed
  • php --ini and php -v - Xdebug not listed

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.