My PHP dev environment is running on a VirtualBox VM and is provisioned via vagrant. How can I use php-debug in Atom on my host machine to debug PHP scripts running on one of my VMs?
Configure xdebug:
Open your php.ini file on your VM and look for the xdebug settings and make sure that you have the following values:
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.remote_mode=req
xdebug.remote_log=/tmp/xdebug.log
xdebug.remote_host=10.0.2.2
xdebug.remote_port=9999
Note: you may have multiple php.ini files, e.g. one for cli, fpm, etc… If you do, you’ll need to make sure that you have the xdebug settings above for all environments where you want to use the debugger, e.g. I had to modify /etc/php5/cli/php.ini to use the debugger on the command line and /etc/php5/fpm/php.ini to use the debugger while running PHP scripts with apache.
Restart your web server or any other PHP related services, e.g.
$ sudo service apache2 restart
$ sudo service php5-fpm restart
Install the php-debug package in Atom:
Go to Atom -> Preferences -> Install, search for php-debug and install the package
Configure php-debug in Atom:
Atom -> Preferences -> Packages, search for php-debug and click
Settings
Set the PathMaps in the form remote;local. The PathMaps
translate the guest/remote path to the local/host path. Let’s assume
that you are debugging foo.php and that it can be found on your VM
at /var/www/mysite/foo.php and on your host box at
/Users/someuser/Documents/vagrant-mysite/foo.php. Your PathMaps
config would then be
/var/www/mysite;/Users/someuser/Documents/vagrant-mysite.
Server Port: 9999
Start debugging:
Open your target source file in Atom, e.g.
/Users/someuser/Documents/vagrant-mysite/foo.php
In the bottom left corner of your Atom screen, click the “PHP Debug” button
Set a breakpoint by clicking immediately left of your target line of code
Visit foo in the browser, e.g. http://example.com/foo.php and this should cause the code to pause in Atom and you should be able to continue debugging
If you configured the php.ini file for your PHP command line settings, you should also be able to debug just by running the script on the guest machine, e.g. php /var/www/mysite/foo.php
Related
I've installed PhpStorm hoping to debug a WordPress site running on my workstation on top of Local (https://localwp.com), which comes with an "Xdebug + PhpStorm" plugin I have installed.
The "zero configuration" has not worked for me. I set breakpoints and request a page in the browser but the breakpoints never get hit.
What else do I need to make this work?
Appendix I
PHP version 7.3.5
PhpStorm 2020.1.3
php.ini
[xdebug]
zend_extension = /Applications/Local.app/Contents/Resources/extraResources/lightning-services/php-7.3.5+8/bin/darwin/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so
xdebug.remote_enable=1
xdebug.remote_connect_back=Off
xdebug.remote_port="9000"
xdebug.profiler_enable=0
In order for PhpStorm / Local / Xdebug combo to work, you'll need to
Start Local
Install the addon for Xdebug from within Local
Restart Local
Start a site in Local (ie test)
Go to Utilities and click "Add run configuration to PhpStorm" (ignore the error that'll pop up)
Start PhpStorm and open ~/Local Sites/test/app/public/app/public . THAT'S IMPORTANT to open the public folder (that contains your WP root)
You'll see a "LOCAL" xdebug dropdown on the top right in PhpStorm
You're all set!
open /app/public from within 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.
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
I have troubles with setting up debugging php cli application. I work on Mac OS and I have here Vagrant with Ubuntu inside, and inside this Ubuntu I have docker. So one of the docker containers runs my php application, where the PHP interpreter lives.
Before (when the application was exactly in Vagrant machine) I was using this command to debug my cli applications, but now it does not work.:
export XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=192.168.10.10 remote_connect_back=0"
How can I set up PhpStorm to debug my php cli app ?
Inside of your Docker container don't use remote_host. Also, you don't have to expose any additional ports in Docker or in Vagrant.
Here is my xdebug.ini file that works with PHP 5.6
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=0
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_connect_back=1
Make sure that PhpStorm (2016.1 in my case) is configured correctly
Languages & Frameworks -> PHP -> Servers -> localhost -> localhost : 80 Xdebug
Languages & Frameworks -> PHP -> Debug -> Xdebug -> Debug port: 9000
Languages & Frameworks -> PHP -> Debug -> Xdebug -> Can accept external connections
Languages & Frameworks -> PHP -> Debug -> DBGp Proxy -> Port 9000
Once this is done find Listen for debugger connections icon in PhpStorm in the toolbar and click it.
If you want to call it from a command line remember to include XDEBUG_SESSION cookie, i.e.
curl 'http://localhost' -sSLI -H 'Cookie: XDEBUG_SESSION=xdebug'
If you use Firefox install The easiest Xdebug and enable it in the toolbar.
In my case, debugging through web browsers worked well, the problmes came with CLI debugging (phpunit). This is because xdebug get lost with path mappings and you need to explicit tell docker.
You need to tell Docker which server configuration in PHPStorm should use, just export that env variable inside your docker container.
export PHP_IDE_CONFIG="serverName=<server-name>"
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).