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.
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"
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.
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
}
]
}
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
Ubuntu 21.10
vagrant up
vagrant ssh-config
copy paste to ~/.ssh/config
php artisan serve
- running from shell to deploy/publish/attach php files to php8.1-fpm
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
artisan
script in root folderphp artisan serve
service php8.1-fpm status
- running in background
/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
sudo service php8.1-fpm restart
after changing /etc/php/8.1/mods-available/xdebug.ini
SomeCustomController.php
file./vscode/launch.json
and php parts from above will be able communicate with it over port 9003
... consider using Laravel Homestead
There could be more than one
php.ini
file. In many set-ups there is a different one for the command line (oftencli/php.ini
) and the web server (oftenfpm/php.ini
)
php-fpm8.1 -m
- Xdebug should be listedphp --ini
and php -v
- Xdebug not listed