How to debug PHP using VSCode IDE in Ubuntu - php

I need to debug PHP code using VS Code IDE. We can debug PHP using Xdebug. So I tried a lots to setup Xdebug for debugging but I failed to use Xdebug using VS Code IDE.
PHP is 8.1
Ubuntu 22.04.1 LTS
Please help me how can I debug.

Step 1:- Install PHP Debug Extension in VS Code IDE.
Step 2:- Copy Full output of Phpinfo(). run below Command in CLI for get output of phpinfo().
php -r "phpinfo();"
Step 3:- open Xdebug wizard Page & paste copied full output of phpinfo() in the form field. after the submitting form you will get step by step Instructions related to setup Xdebug in your System.
In my system currently I used Php 8.1. see below Snapshot of Xdebug Wizard Instructions.
Follow above Instruction which one you will getting from Xdebug Wizard
Note that, above Wizard Instructions is as per my server configuration. In your case it may differ than my above snapshot. So, you must need to follow Step 2 & 3.
Step 4:- add below Configuration in your php.ini file.
[xdebug]
xdebug.mode = debug
xdebug.start_with_request = yes
;Note:- Below Xdebug Path is depends on your OS & your PHP Server.
;So you need to write path of xdebug.so (in Linux)
;OR path of xdebug.dll (in windows)
zend_extension=/usr/lib/php/20210902/xdebug.so
for find Extension Directory for your server (Xampp, Lampp etc. all) then, simply Run php -r "phpinfo();" command then find out extension_dir as like below snapshot
OR write <?php phpinfo() ?> in your php file then run that php file & found out extension_dir in your output page of phpinfo.
Step 5:- Restart your Server (Apache).
Step 6:- Install Browser Extension Initiation. then start debugger in your Vs Code IDE see below snapshot.
Now, All Done.
for referece I share other source urls
refer Xdebug Docs
refer for Windows
refer this for Linux
But, before starts debugging your code, if you need to check Xdebug is working proply or not then Follow below Steps. otherwise you can ignore below steps.
In Xdebug 3+. there is xdebug_info() method exits which return info of xdebug extension.
write <?php xdebug_info(); ?> in your php file & then run this php file.you will get output as like below snapshot
& for check Xdebug works properly for CLI run php -r "xdebug_info();" in cli.

Related

PHP Xdebug Laravel application in IntelliJ IDEA

Could you please advice me how properly configure Xdebug for Laravel application. I found a lot instructions for PhpStorm but they do not work for me as I'm using IntelliJ IDEA Ultimate.
What I have already achieved - I can debug single PHP script but not whole application. I cannot follow completely the instruction which is given for PhpStorm because on step when I need to configure Run/Debug Configuration I got stucked.
Much appreciation on any help in advance!
Okay, I gathered full instruction how to work with XDebug and IntelliJ Idea Ultimate to debug Laravel application and Windows specifically (if you use other OS the installation part will be different but other should be the same):
First of all you need to install XDebug itself and configure PHP to work with it. For that:
Find out which PHP version you use using phpinfo() you will need Version, Architecture and PHP Extension Build sections to complete next step.
Go to https://xdebug.org/download.php and download appropriate build. Basically it is dll provided for specific PHP you have installed
After that copy that DLL to Apache modules directory - for me that is D:\OSPanel\modules\http\Apache-PHP-7-x64\modules\ as I'm using OpenServer.
Put into php.ini file following configuration:
[Xdebug]
zend_extension="D:\OSPanel\modules\http\Apache-PHP-7-x64\modules\php_xdebug-2.6.0-7.1-vc14-x86_64.dll"
xdebug.remote_enable = 1
xdebug.remote_host = "localhost"
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_port=9000
xdebug.idekey="PHPSTORM"
where php_xdebug-2.6.0-7.1-vc14-x86_64.dll is name of dll I personally downloaded.
Restart Apache
Open your Laravel project and check your Debuggin configuration (File > Settings... > Languages & Frameworks > PHP > Debug): check XDebug section if Debug port is the same as you specified above (it should be, if you did not changet it previously)
Delete all your Run/Debug configurations
Install Xdebug Helper for Chrome or any other extension if your not using Chrome (Browser Debugging Extensions)
Hit Run > Start listening for PHP Debug Connections
Put break point in your project and open appropriate site context
Enjoy!
Hope that will be useful for community.

PHP not loading xdebug when started from Eclipse PDT [duplicate]

I have installed Eclipse and xDebug on Ubuntu 10.10.
When I debug some php file as a page, that works fine.
When I try to debug it as a script, I give the message that mysql extension is not loaded.
I set the following options for PHP executable:
Executable path: /usr/bin/php
PHP ini file: /etc/php5/apache2/php.ini
SAPI type: CLI
PHP debugger: XDebug
I wrote the following script:
test.php
<?php
$ext = get_loaded_extensions();
print_r($ext);
?>
When I put in command line /usr/bin/php test.php
I give 50 loaded modules include mysql and mysqli.
When I debug it as a page in Eclipse I give the same modules and xdebug.
When I debug it as a page in Eclipse I give 45 modules include xdebug, but mysql and mysqli are not loaded.
after struggling with this issue for several hours today, I decided to manually cat all informations inside one single .ini file, and started eclipse with eclipse -clean. something like the following script should do the trick:
#!/bin/bash
mkdir /etc/php5/cli_eclipse
cat /etc/php5/cli/php.ini /etc/php5/conf.d/* > /etc/php5/cli_eclipse/php.ini
(you could obviously check if the dir is already existing etc. but this script is here for illustrative purposes only. you'll need to use a superuser account/sudo to execute this).
point your php runtime in eclipse under window -> preferences -> PHP -> PHP Executables to your created file and restart eclipse once with the -clean flag. pdt should create temporary "php.ini"s containing all necessary information.
The Eclipse PDT team decided to introduce the -n option to fix the Bug #324073. So only php.ini from /tmp/zend_debug/... has been loaded, and all additional INI files have not been loaded.
This has been introduced since PDT 2.2.0 M201010110334 (2010/10/11).
For more information, see the following links:
http://redmine.piece-framework.com/issues/242
https://bugs.eclipse.org/bugs/show_bug.cgi?id=339547
https://bugs.eclipse.org/bugs/show_bug.cgi?id=347618
Try invoke the function described here: http://php.net/manual/en/function.php-ini-loaded-file.php and see if it returns exactly the same path.
On Ubuntu as well as on Debian the php configuration is split among many files. Look at the /etc/php5 (or similar path).
As last resort I would write my own config and reference it in the eclipse php run as script configuration and make sure the config includes and references the mysql extension.

While I am debugging PHP Script in Eclipse, it doesn't load mysql extension

I have installed Eclipse and xDebug on Ubuntu 10.10.
When I debug some php file as a page, that works fine.
When I try to debug it as a script, I give the message that mysql extension is not loaded.
I set the following options for PHP executable:
Executable path: /usr/bin/php
PHP ini file: /etc/php5/apache2/php.ini
SAPI type: CLI
PHP debugger: XDebug
I wrote the following script:
test.php
<?php
$ext = get_loaded_extensions();
print_r($ext);
?>
When I put in command line /usr/bin/php test.php
I give 50 loaded modules include mysql and mysqli.
When I debug it as a page in Eclipse I give the same modules and xdebug.
When I debug it as a page in Eclipse I give 45 modules include xdebug, but mysql and mysqli are not loaded.
after struggling with this issue for several hours today, I decided to manually cat all informations inside one single .ini file, and started eclipse with eclipse -clean. something like the following script should do the trick:
#!/bin/bash
mkdir /etc/php5/cli_eclipse
cat /etc/php5/cli/php.ini /etc/php5/conf.d/* > /etc/php5/cli_eclipse/php.ini
(you could obviously check if the dir is already existing etc. but this script is here for illustrative purposes only. you'll need to use a superuser account/sudo to execute this).
point your php runtime in eclipse under window -> preferences -> PHP -> PHP Executables to your created file and restart eclipse once with the -clean flag. pdt should create temporary "php.ini"s containing all necessary information.
The Eclipse PDT team decided to introduce the -n option to fix the Bug #324073. So only php.ini from /tmp/zend_debug/... has been loaded, and all additional INI files have not been loaded.
This has been introduced since PDT 2.2.0 M201010110334 (2010/10/11).
For more information, see the following links:
http://redmine.piece-framework.com/issues/242
https://bugs.eclipse.org/bugs/show_bug.cgi?id=339547
https://bugs.eclipse.org/bugs/show_bug.cgi?id=347618
Try invoke the function described here: http://php.net/manual/en/function.php-ini-loaded-file.php and see if it returns exactly the same path.
On Ubuntu as well as on Debian the php configuration is split among many files. Look at the /etc/php5 (or similar path).
As last resort I would write my own config and reference it in the eclipse php run as script configuration and make sure the config includes and references the mysql extension.

PHP Zend Debugger configuration

Hi i am new to php, I currently learning php using eclipse. I know i have to install the zend debugger my php.ini store at c:windows i had added in these line:
[Zend]
zend_extension=c:/php/ext/ZendDebugger.dll
zend_debugger.allow_hosts=127.0.0.1
zend_debugger.expose_remotely=always
zend_debugger.connector_port=10013
but on command prompt i tried php -m it shown that i never install zend debugger. I not sure where goes wrong I check phpinfo also never show any zend information.
I had lots of problems making the debugger work. Now I'm using the ZendServer CE which is free and the configuration is a lot easier.
Also I use Eclipse + PDT, downloaded from Zend Site.
This should work right out of the box. Why not using ZendServer? you get everything you want in a package.
On a browser go to:
http://localhost/?phpinfo=1
look for "Loaded Configuration File"
and take a note of the path
Now open a DOS prompt window (Start > Run > (type) cmd)
and at the command line type
c:\path\to\your\php\php.exe -r phpinfo(); |more
(press CTRL+C to break)
Again look for:
"Loaded Configuration File"
and take a note of this path.
It could be that you are using a different php.ini for your webserver and for the CLI version.
You will need to add the config changes to both php.ini files or put the config in a file called zend.ini and place that in the folder that is mentioned in your phpinfo output under:
"Scan this dir for additional .ini files"
I have experienced the same thing when I was using thread-safe PHP on Windows.
Up to date versions of the Zend Debugger no longer support running in thread-safe flavors of PHP on Windows. Switching to a non-thread-safe (a.k.a nts) flavor of PHP fixed this issue for me.
See here: http://forums.zend.com/viewtopic.php?f=59&t=1918#p13729

how can i associate/use PDT with eclipse in ubuntu?terr

I want to use PDT to debug PHP with eclipse. I am using ubuntu 9.04.
Can any one help me? please give details if possible.
Considering this thread and this one:
You have to ensure that xdebug is definitely loaded on the version of php you are using.
To do this, use the launch configuration you are using to try to run your script in debug mode and change it to run a script with phpinfo.php in it.
Also a Debug log would be good.
Add:
xdebug.remote_autostart=On
xdebug.remote_log="c:\temp\xdebug.log"
to your php.ini.
Then you have to insure that PDT is expecting Xdebug information on port 9000,
and have insured that your local Default PHP Web Server is http://127.0.0.1.
With the log, you might discover, for instance, that your php.ini files is not properly formatted, which could be enough to prevent you debugging PHP from PDT.
UYu would have to install PHP5 xdebug extension first,
sudo aptitude install php5-xdebug
after you would have to check your settings by editing /etc/php5/conf.d/xdebug
after you have to setup your php project to use xdebug and you should be done.
I'm use PDT in Ubuntu 9.04 and can fine debug my php projects.
first as already answered install php5-xdebug through apt-get or synaptic (I'm think you already install php5 itself in same way :) ). Then you must define php executables in Window/Preferenses/PHP/PHP Executables. You can point to /usr/bin/php, or can use 'Search...' button, but you must point initial search dir to nearest to your php exec binary. After found executable it always set to use Zend Debug by default. Edit executable to change 'PHP debugger' type to XDebug. And now a main trick. When you try debug your php scripts without create run configuration - it will always use Zend Debugger. You must create your own run configuration with XDebug setted as PHP Debugger. It's worked for me.

Categories