Using xdebug with PhpStorm - php

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 :)

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.

Symfony 3: Debugging with Symfony's development server

During the development on a Symfony 3.3 project I use the Symfony's internal server as seen there But I cannot figure out how to use the xdebug in order to debug it. I mean I have installed and configured xdebug via:
apt-get install php-xdebug
And I export:
export XDEBUG_CONFIG="idekey=phpstorm"
But when I put a breakpoint to my IDE and I enable the xdebug via that plugin I still get no response.
Also I have put the following settings on /etc/php/7.0/mods-available/xdebug.ini
zend_extension=xdebug.so
xdebug.remote_enable=On
xdebug.remote_autostart=On
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9021
xdebug.remote_mode=req
And I have configured both PhpStorm to listen over port 9021. But I still get the problem that I cannot make PhpStorm to listen over a breakpoint.
Do you fellows have any sort of idea how I can fix that over my ubuntu-16.04 machine?
Furthermore I have looked on these questions without any success:
Xdebug configuration with PHP fastcgi and eclipse?
Is it possible to use Xdebug with the built in PHP test server?
EDIT 1
I also tried to export the following:
export XDEBUG_CONFIG="idekey=PHPSTORM"
An configuring the Firefox plugin but still get the very same behaviour. Also keep in mind that I made the PhpStorm to listen over xdebug by pressing the button.
EDIT 2
I also put the following configuration over my PhpStorm:
Still does not work.
In the end the following steps are needed:
Put the following content into: /etc/php/7.0/mods-available/xdebug.ini
zend_extension=xdebug.so
xdebug.remote_enable=On
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9021
xdebug.remote_mode=req
Export:
export XDEBUG_CONFIG="idekey=PHPSTORM"
Then configure PhpStorm as the image shows.
Set as IDE key PHPSTORM into the Firefox plugin
Enable xdebug on Firefox via pressing the button. Alternatively you can append the url with ?XDEBUG_START part
Then press the button in PhpStorm. In case you see the then press it back again.
NOTE:
In case you change xdebug settings TERMINATE the xdebug session by pressing button and pressing back again.
Furthermore in case you run composer via terminal disable PhpStorm to listen xdebug by pressing button.

Problems installing xdebug.so extension on local AMP environment

Edit: I've now removed the version of xdebug.so I installed manually, and installed XDebug via Homebrew. When I type "php -i" at the command line, xdebug appears to be installed; but when I run phpinfo(), there's still no sign of XDebug.
I've just got a new Mac so, like every time I buy a new Mac, I have rebuilt my local web development environment (this time, following an amazing tutorial: https://echo.co/blog/os-x-1010-yosemite-local-development-environment-apache-php-and-mysql-homebrew)
Everything has gone smoothly until I got to installing the XDebug extension. I use Komodo as a development environment so, as I've always done in the past, I followed the instructions here: http://docs.activestate.com/komodo/7.1/debugphp.html#debugphp_top
I followed the instructions to the letter, but I can't get xdebug.so to appear in my phpinfo.php() page. Here's what I did:
Created a phpinfo.php file so that I can find the correct php.ini file
Checked that phpinfo.php file and found that the "Loaded Configuration File" is "/usr/local/etc/php/5.6/php.ini"
Edited that php.ini, adding the following lines to the bottom of the file:
_
zend_extension=/usr/local/Cellar/php56/5.6.14/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.idekey=<idekey>
; You may also want this - to always start a remote debugging connection.
;xdebug.remote_autostart=1
Ran "brew services restart httpd22" (and, just to be sure, "sudo apachectl restart")
When I go reload phpinfo.php, it contains to reference to xdebug.so.
I can confirm that xdebug.so is present at /usr/local/Cellar/php56/5.6.14/lib/php/extensions/no-debug-non-zts-20131226 and that /usr/local/Cellar/php56/5.6.14/lib/php/extensions/no-debug-non-zts-20131226 is set as the "extension_dir" in php.ini.
What am I missing?!
Ultimately this proved be to be caused my me doing things in the wrong order. I'd used Homebrew to install Apache and PHP, but I'd installed Apache 2nd: this meant that it wasn't set up to work with the version of PHP I then installed.
I reinstalled PHP using the command brew reinstall php54 --homebrew-apxs, and that ensured that Apache and PHP were talking to each other.
Then, to install xdebug, I ran brew install homebrew/php/php56-xdebug. After restarting Apache, XDebug showed up in phpinfo() straight away!
Then I had to get XDebug talking to Komodo. To do this I added in the config lines from my original post to the specific xdebug config file that had been created during the Homebrew install (mine was located at /usr/local/etc/php/5.6/conf.d/ext-xdebug.ini), and then made sure that Komodo was listening on the correct port (9000 didn't work, so I changed to 9001).

XDebug could not connect to client

I am trying to debug with NetBeans Mac locally.
This is my php.ini
[xdebug]
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_log="/Applications/MAMP/logs/xdebug.log"
xdebug.idekey="netbeans-xdebug"
zend_extension="/Applications/MAMP/bin/php/php5.4.10/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so"
This is what I had been getting in xdebug.log
I: Connecting to configured address/port: localhost:9000.
E: Could not connect to client. :-(
I try changing the port to 9001 and turn off firewall and it didn't help.
Xdebug's default port (9000) conflicts with FastCGI (Xdebug was first!) - the solution is to change it to another port. After having done that, you need to restart your IDE where you will also need to configure the new port. You will also need to restart PHP and your Web Server.
Step 1:
Change xdebug.remote_port=9000 to xdebug.remote_port=9001
Step 2:
Change the debugging port in Netbeans. Go to Tools >> Options >> Click PHP tab
Under PHP tab click debugging
Change the debugger port : 9001
Change Session ID : netbeans-xdebug
Step 3:
Restart server and netbeans
Step 4:
Set a breakpoint and try
I had exact the same problem.
The xdebug installion wizard (https://xdebug.org/wizard.php) showed that my xdebug was correctly installed. (The wizard told me to install the Xdebug 2.5.0rc1 dll)
In phpinfo I also got a xdebug section showing (in my opinion) the correct values. Even with this I got a "could not connect to client" message in the error log.
Eventually I solved it by trial and error doing the following:
Downloaded all the older versions of the xdebug dll's for my php version and tried them all. Eventually one of them worked. For me it was with php 5.6.8 the xdebug 2.4.1 dll (PHP 5.6 VC11 TS (32 bit) ) on a windows 7 32 bit machine. I am using xampp-win32-5.6.8-0-VC11.zip for my xampp installation.
What I learned was the following:
(a) The Xdebug wizard does not neccesarily give the correct dll to use
(b) Even though phpinfo shows a Xdebug section with correct variables this does not necessarily mean that it is correct.
(c) Try older versions of the dll's if you get this error.

No xdebug in phpinfo()

I have added following lines into php.ini
[XDebug]
zend_extension = C:\PROGRA~1\PHP5\ext\php_xdebug-2.1.0-5.3-vc9.dll
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
Version of php_xdebug-2.1.0-5.3-vc9.dll is obtained via page http://www.xdebug.org/find-binary.php.
But there are no any mentions of 'xdebug' string in output of phpinfo().
What can be wrong?
(This is my second fight with php-xdebug to get working, first time I gave up. If you have other suggestions concerning debugging please add them also, possibly as comments to the question. I would like to following scenario work under windows: "Set up break point, run my script, it stops on break point and I can see the value of some variable". Thanks)
UPDATE
Restart of Apache does not resolve the issue.
In log file the message appears:
Apache/2.2.14 (Win32) PHP/5.3.1 configured - resuming normal operations
check the top of the output of
php -m
for me it showed an error in php.ini, after solving that xdebug was loaded.
zend_extension = C:\PROGRA~1\PHP5\ext\php_xdebug-2.1.0-5.3-vc9.dll
should be replaced by
zend_extension="C:\PROGRA~1\PHP5\ext\php_xdebug-2.1.0-5.3-vc9.dll"
P.S. Will e-mail xdebug guys.
This worked for me (vscode, xampp)
Go to https://xdebug.org/wizard.php and paste the contents of phpinfo()
Then download the right xdebug.dll and place it in your 'ext' folder.
Add the following to your php.ini
[XDebug]
zend_extension="php_xdebug-2.5.4-7.0-vc14.dll"
xdebug.remote_enable=1
xdebug.remote_autostart=1
I just had the same problem, nothing of this worked for me.
I started php in the console and I saw, php was unable to load the dll from the given path.
The solution for me was to omit the path information and only load it like this:
zend_extension="php_xdebug-2.2.5-5.5-vc11.dll"
You can follow this tutorial on getting started with xdebug : http://devzone.zend.com/article/2803-Introducing-xdebug
Xdebug and ZendDebug are two separate debuggers, it's up to you to decide which one to use. Either one is pretty easy to setup. Only a couple of steps in Eclipse.
Post the content from your php info page into this page to find out which version to download : http://www.xdebug.org/find-binary.php
I was just struggling with this myself and found a way to identify (and solve) the problem. It works on Xampp and Windows 7 at least.
In my case the problem was dots. Renaming "php_xdebug-2.2.5-5.5-vc11.dll" to "php_xdebug.dll" did the job.
Another pro-tip is that newer versions of Xampp have Xdebug built-in, so you don't need to donwload it, just edit php.ini with:
zend_extension = "path\to\php\ext\php_xdebug.dll"
xdebug.remote_enable = on
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1 (or localhost)
xdebug.remote_port = 9000
xdebug.remote_mode = req
Then restart the apache and it should work. The advantage of using xampp built-in xdebug is that it's most likely the right version.
Writing in January 2019, I found that following the Xdebug Wizard at Xdebug wizard here
exactly, including using their download link to the correct version of Xdebug for your version of PHP and copying the line to insert on your php ini exactly as is, got Xdebug appearing in phpInfo for me. I was installing into Laragon . Running php -m from the command line gave a good confirmation of all being well, with Xdebug loading as a Zend Extension. Usual gotchas about needing to restart server etc apply.
In my case, Xdebug is showing in php -m, php -i but not in phpinfo() result.
Restarting Apache didn't help until restarting php-fpm
systemctl restart php-fpm.service
Its happen because of permission.
you have to add the permission of that specific app/user profile from the folder's Properties Security tab.
I use PHP with IIS server so.
It worked for me by adding IIS_USER in security permission.
in my case the issue was the php.symlink file in the C:\wamp64\bin\apache\apache2.4.23\bin folder , this file links to the php.ini file existed in C:\wamp64\bin\php\php5.6.25 but apparently it wasn't working so i've deleted it and copy paste the actual php.ini to the same folder and it worked.
if you want to return the php.symlink back open cmd in the
C:\wamp64\bin\apache\apache2.4.23\bin and write the following (windows):
mklink php.ini C:\wamp64\bin\php\php5.6.25\php.ini
replace the path to point to your php.ini inside your php file
Just for the newbees:
If you want to check if the .dll, specified in the php.ini is loading properly:
Add php to the Windows Runtime Directory. For win10, refer to this post https://www.forevolve.com/en/articles/2016/10/27/how-to-add-your-php-runtime-directory-to-your-windows-10-path-environment-variable/
From the Windows command prompt, type php -m and check if any error is displayed.
In my case the issue was the file path which apache loaded, the file php.ini I changed is not the current loaded config, so check it First.
xdebug appears in "php -m" command line BUT nothing on the browser <?php phpinfo(); page !
Check in httpd.conf PHPIniDir "C:/to/the/RIGHT/phpversion"
The command line php.exe use the Environment PATH variable but nut the apache !

Categories