How to install PHP Xdebug in Eclipse on Windows? - php

I have a PHP file and I want to debug that file in Eclipse. I have heard about Xdebug as the best way to debug a PHP file in Eclipse.
What are the steps needed to be able to debug PHP files in Eclipse? I am using Windows OS.

Download PHP for eclipse (PLUGIN eclipse)
Use update URL
https://download.eclipse.org/tools/pdt/updates/7.0
Download XAMPP for windows and install it
https://www.apachefriends.org/es/download.html
Now you can follow alternative instructions here or continue to the next point where i explain what you need to do.
http://robsnotebook.com/php_debugger_pdt_xdebug
After installing XAMPP you should start Apache
Download Xdebug e.g http://xdebug.org/files/php_xdebug-2.9.2-7.2-vc15-x86_64.dll and check if it is correctly installed. Follow next instructions
1. Download php_xdebug-2.9.2-7.2-vc15-x86_64.dll.
2. Move the downloaded file to C:\xampp\php\ext
3. Update C:\xampp\php\php.ini and change the lines
[XDebug]
;; Only Zend OR (!) XDebug
; zend_extension_ts="C:\xampp\php\ext\php_xdebug.dll"
; Modify the filename below to reflect the .dll version of your xdebug
zend_extension = C:\xampp\php\ext\php_xdebug-2.9.2-7.2-vc15-x86_64.dll
xdebug.remote_enable=true
xdebug.remote_host=127.0.0.1 ; if debugging on remote server,
; put client IP here
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.profiler_enable=0
xdebug.profiler_output_dir="C:\xampp\tmp"
4. Restart the XAMPP webserver in your XAMPP control Panel
Comment out any Zend Optimizer in php.ini because it is not compatible with XDebug. For example, all of this should be commented out (using “;”):
[Zend]
; zend_extension_ts = "C:\xampp\php\zendOptimizer\lib\ZendExtensionManager.dll"
; zend_extension_manager.optimizer_ts = "C:\xampp\php\zendOptimizer\lib\Optimizer"
; zend_optimizer.enable_loader = 0
; zend_optimizer.optimization_level=15
;zend_optimizer.license_path =
Check that it is working with phpinfo. You go to your browser and go to:
http://localhost/dashboard/phpinfo.php
Or create in your c:/xampp/htdocs
A file calling phpinfo e.g.
http://localhost/phpinfocall.php
Configuration PHP debug in eclipse
You can create a PHP project. That project should be pointint to C:\xampp\htdocs
The C:\xampp\htdocs is the localserver root folder in xampp. Inside you can create subfolders.
Configure PHP Preference of eclipse
Connect eclipse with php parser of xampp
Configure this and check that xdebug is detected in eclipse from xampp
How to create a debug view from a PHP file in your project
Debug view configuration below,
Lastly, you will see in the debug perspective, that the debugger stop automatically on the first line of your php file.

Related

How to debug PHP using VSCode IDE in Ubuntu

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.

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.

Using xdebug with PhpStorm

I can't get my PhpStorm IDE to work with xdebug.
My current setup is the following:
PhpStorm 2017.1.4
MacOS Sierra 10.12.5
Here are the steps that I followed.
I have installed php with the following command. I have added the postgres parameter because I need it later to connect to a PostgreSQL database.
brew install php71 --with-postgresql
The next step is to install XDebug with the following command
brew install php71-xdebug
So the next step that I got from the documentation (https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html) is to edit the php.ini file with the following content:
[Xdebug]
zend_extension="<path to php_xdebug.dll>"
xdebug.remote_enable=1
xdebug.remote_port="<the port for Xdebug to listen to>" (the default port is 9000)
xdebug.profiler_enable=1
xdebug.profiler_output_dir="<AMP home\tmp>"
Just some questions about those fields and XDebug.
So I guess XDebug is some kind of service that runs on the remote_port and that PhpStorm is using to write data to? Or do you have to specify the port where the application you want to test is running?
What exactly is the profiler thing? And can the output dir be anything I can choose?
So this is my php.ini file that I think it should be:
[xdebug]
zend_extension="/usr/local/Cellar/php71-xdebug/2.5.4/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/usr/tmp"
That's it for the php.ini. So I have to check the settings in my PhpStorm IDE. And those are the following:
So that is my setup. In my project I just have one index.php with <?php echo phpinfo(); ?> I just click the Chrome icon so it opens directly in the browser to check if XDebug is there. I see the following result.
So I thought to myself ok let's try some debugging. So I changed my index.php file to the following
$i = 2;
$j = $i + 2;
echo $j
I've put a breakpoint on the 2nd line. And when I run it, it never stops at the breakpoint. What is needed to do that or am I wrong in my configuration somewhere?
To make Xdebug remote debugging working on your page, you need to set a cookie in your browser, telling the server you want to debug the page, there are many extensions for that, the most known is Xdebug helper in Chrome.
I also suggest you to follow this tutorial Zero-configuration debugging, it is very detailed and clear IMO.
If you still have problems i'll try to help you with pleasure :)

xdebug 2 with PhpStorm setup error

I have been dealing with an unexpected error when trying to setup xdebug 2 with PhpStorm (2016.2.2). It says:
Connection with 'xdebug 2.5.0rc1' was not established. Validate installation.
I decided to ask for help because I cannot solve this error for 3 days already and I have tried everything I could.
These are the setup steps that I did:
pasted my phpinfo here (https://xdebug.org/wizard.php) and downloaded the recommended php_xdebug.dll (php_xdebug-2.5.0rc1-5.5-vc11-nts-x86_64).
copied php.ini file into bin\php\php5.6.0 and added these lines of code:
[Xdebug]
zend_extension = C:\MAMP\bin\php\php5.6.0\ext\php_xdebug-2.5.0rc1-5.6-vc11.dll
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.idekey=PHPSTORM
xdebug.remote_port = 80
xdebug.profiler_enable=1
Installed "JetBrains IDE Support" and "Xdebug helper" extensions for Chrome browser.
Sometimes I manage to debug (I guess) without an error but I get an error on browser which says "No direct script access allowed".
I am on Windows 10 x64 running MAMP 3.2.2 with php 5.6.0. Don't know what more details I can provide right now but it looks enough.
The problem that I had was on the other laptop that I use. Both of them use the same settings (win10, MAMP 3.2.2). On my second laptop (the one I am currently typing from) this is php.ini settings:
PHP version: 5.6.0 PHP CLI: C:\MAMP\bin\php\php5.6.0\php.exe PHP CGI:
C:\MAMP\bin\php\php5.6.0\php-cgi.exe Loaded Configuration File:
C:\MAMP\bin\php\php5.6.0\php.ini Debugger extension: xdebug 2.4.1
It uses xdebug 2.4.1 and I dont get the error on this laptop. I will try to get the same xdebug version to my first laptop and see if it works.
And this is the only command I added to php.ini on the second laptop (xdebug functioning) "zend_extension = C:\MAMP\bin\php\php5.6.0\ext\php_xdebug-2.4.1-5.6-vc11.dll" . Does it even make sense that without extra Xdebug settings it could even run?

Netbeans xDebug only runs once on Mac

I'm running Netbeans on my Mac. I installed my local server using XAMPP and have installed xDebug. When I go to debug/breakpoint in Netbeans, I can get it to run the first time on index. However, after the first run it won't attach to xDebug again unless I restart Netbeans.
How can I make sure that Netbeans always attaches to xDebug? Also, how do I get Netbeans to debug something besides the index file?
In your php.ini add following
; XDEBUG Extension
zend_extension = "**ABSOLUTE_PATH_TO_XDEBUG_EXTENSION**"
[xdebug]
xdebug.remote_enable = off
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir = "**PATH_TO_TMP_DIRECTORY**"
In NetBeans IDE go to Tools > Preferences > PHP > Debugging
Debugger Port: 9000
Session ID: netbeans-xdebug
CHECK : Stop at First Line
Open your project. Go to Project Properties > Run Configuration. Set
Run As: Local Web Site (running on local web server)
Project URL: http://localhost/PROJECT_PATH/
Index File: index.php
Save your project file
Restart Apache
Restart NetBeans, open project, then
Debug > Debug Project
You should see http://localhost/PROJECT_PATH/index.php?XDEBUG_SESSION_START=netbeans-xdebug in the browser and NetBeans should stop at the first line of index.php
Might be problem with incompatible version of xdebug. For example downgrading xdebug from 2.2.4 to 2.2.3 solves the problem. http://bugs.xdebug.org/view.php?id=1038
Try deleting all files on your tmp dir set on xdebug.profiler_output_dir
I had a similar situation where xdebug would work only "once" - on the first page load. After I emptied the tmp folder it worked ok.

Categories