xdebug in a laravel project in ubuntu 16.04 using sublimetext 3 - php

I'm moreless new with this kind of things, I'm trying to setup xdebug to debug a laravel project I'm developing in my Ubuntu 16.04, I have installed sublime text with the package control and the xdebug client, I installed from apt-get the packages
php (7.0) php-xdebug php-all-dev php-fpm
the laravel project already works with the comand
php artisan serve
I saved the sublime text 3 project with the code
{
"folders":
[
{
"follow_symlinks": true,
"path": "."
}
],
"settings": {
"xdebug": {
"url": "http://localhost/",
}
}
}
my /etc/php/7.0/fpm/conf.d/20-xdebug.ini is:
zend_extension=xdebug.so
xdebug.remote_enable = 1
xdebug.remote_handler=dbgp
xdebug.remote_host=127.0.0.1
xdebug.remote_port = 8000
xdebug.remote_log="/var/log/xdebug/xdebug.log"
I dont know if I need to use the "php artisan" to debug or just with the xdebug plugin in sublime text, nothing apear to work
any ideas?
thanks for everything

Here is my config for xdebug:
zend_extension=/usr/lib/php/modules/xdebug.so
xdebug.remote_enable=on
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.idekey="netbeans-xdebug"
xdebug.remote_autostart=1
Note the remote_autostart, which made all my debugging work correctly.
I don't use sublime, but this config worked correctly in Atom, PhpStorm, VSCode and Netbeans, and I assume it will work virtually for all compatible debugger clients. Make sure that the port, host and idekey fields are the same in sublime and your config file, that's all.
The thing is, you have to know how xdebug works. Then you can set it up everywhere easily.
xdebug works but connecting to the remote_host and remote_port you specify in its config. That means, when a PHP script is going to be executed, first, if loaded, xdebug tries to connect to that address. If a compatible debugger is listening on the other side, then connection is made, and the debugger can do its debugging. Note that, xdebug, as in sockets terminology, is a client to your server (ide, debugger, ...). So your ide must be listening first, before PHP script is executed. In sublime, find something like listening for connections.
For debugging if problem is with your ide or xdebug itself, you can use debugclient, a tool that acts as a server for xdebug. Just run debugclient and execute a PHP script, with xdebug loaded (which seems you have it). If it shows that connection is made, than sublime has a configuration problem. If not, check xdebug config again, and make sure everything is ok.
I have seen systems where debugclient is not installed by default. You can also test with nc -l 9000 or whatever port to test it too.

Related

PHP Xdebug with NetBeans and Apache

I’m trying to do my first steps with PHP. I decided to use NetBeans, which seams helpful.
NetBeans is running on my local Windows machine. My testpage is running on an Apache2 webserver in my Ubuntu HyperV M.
Up to now everything works fine. Now I enabled remote debugging over Xdebug. Therefore I added the following lines to the php.ini:
[debug]
; Remote settings
xdebug.remote_autostart=off
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=192.168.2.20
xdebug.remote_port=9000
The connection is ok and debugging works. Unfortunately the debugger stops at each line and not only at my breakpoints. That makes my tests inefficient. Therefore my question is how to tell NetBeans to stop at breakpoints only?
Found the solution by myself. There is an option "stop at first line" in the Netbeans PHP debugging settings. Removing that did the trick.

Trying to install Xdebug on my remote server with PhpStorm

I have a remote machine where runs an Apache Server. I want to use Xdebug on my local machine, using PhpStorm, to debug the PHP files located in my remote server.
Here is what I did on my remote Ubuntu server :
1. apt-get install php7.2-xdebug
2. Go to /etc/php/7.2/apache2/php.ini and add :
[xdebug]
zend_extension=/usr/lib/php/20180731/xdebug.so
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.remote_host=<my local machine IP without braces>
xdebug.remote_log="/var/log/xdebug.log"
xdebug.idekey=PHPSTORM
3. Restart Apache server /etc/init.d/apache2 restart
4. When I create a script with echo phpinfo(); in it, it shows that Xdebug has been installed "correctly" (I guess) : it shows an Xdebug section with all the variables.
5. In PhpStorm, I set a breakpoint on a file, and I start listening to incoming debug sessions, I verify this by doing a netstat query that returns that my Mac has its process PhpStorm listening to port 9000
6. In Chrome browser, I download the extension Xdebug, and I open my script, where I added the breakpoint. The mapping between this file that I open in Chrome and the local files is correct.
7. I tap the button "debug" in the Chrome extension, it becomes green. I verified, the cookie is correctly sent as http headers has XDEBUG_SESSION=PHPSTORM
Despite all of this, I cant achieve to have any incoming session on PhpStorm.
I tried to see file /var/log/xdebug.log that I registered to be the log file of Xdebug, but this file is empty....
Did I forget something ? I have no idea what to do its been 8 hours I'm on it I have seen all post related to it on StackOverflow but nothing worked for me (I can't even manage to have something in /var/log/xdebug.log so I could see deeper what's going on). I have no idea if Xdebug is doing something when it receive my HTTP request.
you phpstorm'configure is maybe error.

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

PhpStorm and XDebug on Vagrant Homestead

I'm on Windows and I'm trying to debug a Web application (hosted with Vagrant/Homestead) using PhpStorm through XDebug. I tried many configurations but I can't get things working. The PhpStorm XDebug setup is pretty common.
This is the current xdebug configuration:
vagrant#homestead: /etc/php/7.0/cli/conf.d/20-xdebug.ini
zend_extension=xdebug.so
xdebug.remote_enable = on
xdebug.remote_connect_back = on
xdebug.idekey='PHPSTORM'
In the IDE "Start listening for PHP debug connections" it's turned on. When I attempt to start debugging a new chrome tab opens and the URL ends, for example, with ?XDEBUG_SESSION_START=16588 but the debugger doesn't run and this is what the IDE says:
Also, netstat says the port 9000 is still listening.
Any idea?
You are changing the 20-xdebug.ini file for the Command Line Interface (CLI). Instead you need to change the /etc/php/7.0/apache2/conf.d/20-xdebug.ini for the Apache settings, since you are using Chrome.
UPDATE
I'm not sure of the differences between Apache and Nginx (which may be /etc/php/7.0/fpm/conf.d/20-xdebug.ini), but here is how I got it working with a VirtualBox VM running Apache, on a Windows computer.
Settings for 20-xdebug.ini:
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=192.168.1... (your windows IP address within your network)
xdebug.remote_port=9000
xdebug.autostart=1

Debug VM with xDebug and PhpStorm

My work setup is a Windows XP host, running an Ubuntu VM LAMP stack. I am using PhpStorm to edit my code on my host Windows machine. Upon saving files are automatically uploaded to the VM via SFTP. Everything works for this process, except debugging.
I have setup PhpStorm to have a server named "UbuntuVM" with the following settings:
Debugger:
- XDebug
Debug session settings:
- Break at the first line
- Wait for connection with ide key: XDEBUG_PHPSTORM
Before launch:
- Upload files to selected server
I am using Chrome with Xdebug Helper, and have set the extension to use "Other" as the IDE, with "XDEBUG_PHPSTORM" as the key.
The VM has the following in the php.ini:
zend_extension="/usr/lib/php5/20090626+lfs/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=10.1.6.22
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.collect_params=On
xdebug.show_local_vars=On
When I set a break point in my IDE, enable the debugger in Chrome, and reload the page, I never hit the break point; and the IDE says "Waiting for connection on port 9000 with ide key 'XDEBUG_PHPSTORM'".
Does anyone have any idea why I'm not hitting my break points?
Comes to find out that xdebug.remote_host isn't needed, rather, use xdebug.remote_connect_back=1.

Categories