Our project environment configured by Docker and program language is PHP.
I want configure the Xdebug to debug the program.
Because the code mapping to the dockers, and runtime environment on the Docker, I can't configure the xdebug directly.
Now, I meet some questions:
This is web service validation shot, it has 2 warnings:
This is php.ini with Xdebug:
This is Xdebug log:
The service name is correct. How do I do?
Related
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>"
I'm trying to get PHPStorm to work with Xdebug to use with PHP scripts (CLI, not web pages!) on a vagrant instance on the same machine as PHPStorm is running on.
In their docs they say this:
To tell the PhpStorm which path mapping configuration should be used
for a connection from certain machine, the value of the PHP_IDE_CONFIG
environment variable should be set to serverName=SomeName, where
SomeName is the name of the server configured in Settings /
Preferences | Languages & Frameworks | PHP | Servers:
Windows: set PHP_IDE_CONFIG="serverName=SomeName" Linux / Mac OS X:
export PHP_IDE_CONFIG="serverName=SomeName"
However, it's unclear where I'm supposed to set this-- is it set somewhere in the PHPStorm app? Is it set as part of the bash profile in the vagrant box? In the vagrant xdebug conf?
A per LazyOne comment, PhpStorm since v8 supports debugging CLI scripts over SSH directly (via Remote PHP Interpreters)-- there you do not need to do anything like that. But you may need to setup SFTP deployment and use that when creating Remote PHP Interpreter (it depends: in some cases IDE cannot use/interpret path mappings from vagrant config file.
See:
https://confluence.jetbrains.com/display/PhpStorm/Remote+debugging+in+PhpStorm+via+SSH+tunnel
https://confluence.jetbrains.com/display/PhpStorm/Working+with+Remote+PHP+Interpreters+in+PhpStorm
I am trying to find a way to debug PHP other than var_dump() and I noticed Xdebug. I cannot find on the internet if Xdebug has a command-line version (I dont want to use a GUI version, bear with me(sshing another linux system)). If there is, how can I use it? If no, is there any other PHP debugging tools that can be run as command-line?
xdebug
Profiler:
With xdebug, you might run the profiler from CLI with this command:
php -d xdebug.profiler_enable=1 script.php
In order, to run this on the console, the box you are ssh'ing into must have PHP and Xdebug installed and configured.
Remote Xdebug:
Another option would be to use xdebug.remote_host with SSH tunneling/forwarding.
Forwarding is described here: http://derickrethans.nl/debugging-with-xdebug-and-firewalls.html
Remote Xdebugging here: http://xdebug.org/docs/remote
This allows to work with Netbeans or PHPStorm on the remote machine.
Xdebug's DebugClient
You might also use the simple DebugClient xdebug ships for CLI usage.
Every other debugging client, which supports the dbg-protocol, should work, too. http://xdebug.org/docs/install#debugclient
phpdbg
If you run PHP 5.6, then you might use phpdbg, which is the integrated debugger and perfect for CLI usage.
How should I configure PHPStorm so that I can trace my code using XDebug when running console commands?
I know I have the debug configuration correct, because I can debug web requests and trace the code. I can also trace regular php command line scripts as long as I set an environment variable like this:
export XDEBUG_CONFIG="idekey=my-xdebug"
However, I am unable to trace/debug Symfony2 console commands (those run with app/console bundle:console_command). PhpStorm sees the connection, however, it can't seem to locate the code that is being run. I know my file mapping is correct because web requests work flawlessly.
Is this possible?
You should provide SERVER_NAME and SERVER_PORT. also you should enable xdebug.remote_autostart. Try this:
SERVER_PORT=<Your port> SERVER_NAME='<Your server> php \
-dxdebug.remote_autostart=On app/console test
Make sure you have enabled xdebug inside php.ini CLI version not only apache/cgi php.ini.
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_host = 127.0.0.1
xdebug.remote_port = 9000
xdebug.idekey = PHPSTORM
I'm suggesting to try following BASH helper command:
https://github.com/torinaki/phpdebug-cli
phpdebug mostly autodetects all required configurations and you will not require to provide environment variables.
Just run:
phpdebug app/console bundle:console_command
I've seen these answers: debugging php on mac?
but I am hoping that there is a better/newer solution. I am a system-level developer (C/C++/x86) but totally new to the web/scripting space. I feel that I would do well do setup a solid debugging environment - it is usually a great way for me to learn.
Any suggestions/pointers as to a good php debugging setup on a Mac (10.6) would be much appreciated.
Thanks,
Matt
I'm a Mac user myself and since I do some heavy PHP development, I need an elaborate setup for this.
First of all, the standard PHP and Apache installed in Snow Leopard isn't bad, but upgrading or adding extensions to it is quite a task. To be able to fully control the environment, I decided to install the entire AMP stack using MacPorts. Don't worry about overwriting existing files, as everything will be installed in separate locations. Just make sure you disable the stock Apache before starting the newly installed one. There are loads of tutorials on how to get this done.
My IDE of choice is Komodo IDE. This IDE comes out of the box with integrated debugging using a preconfigured xdebug setup. I have ended up compiling and using the latest xdebug version instead of the stock version for compatibility reasons (PHP 5.3+). Many developers use the aforementioned Eclipse + PDT which offers a similar IDE, although slightly more has to be done to get it configured properly.
For remote debugging I have configured the PHP module in apache to load xdebug also and connect to my running IDE. More info about that can be found here. For complex web applications it is ideal if you can just open the browser, navigate to the correct webpage and activate debugging to step into the first line of code of that page.
For performance testing and tuning I use the profiling feature of xdebug. When enabled, xdebug will write callgrind files to a specific directory. I use MacCallGrind to visually analyse the profiler files. There is a free alternative called KCacheGrind which can be installed if you enabled MacPorts (as mentioned in the first suggestion).
I use this environment to develop pretty complex and large multi-homed projects, involving commandline (daemonized) PHP applications that utilize forking and IPC structures and extensions like memcache. I'm quite satisfied with how this setup works for me.
There is a way how to do it using:
PhpStorm
Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Php + Xdebug
1) Install php and debug
brew install php70
brew install php70-xdebug
In PhpStorm - check Preferences => Language and Frameworks => PHP
Php language level: 7
Interpreter: PHP 7.0.8 + XDebug (or choose from [...])
Check debug config:
Preferences => Language and Frameworks => PHP => Debug => Xdebug section
All checkboxes should be checked and set Debug port to: 9001
2) run server in your app's directory:
php -S localhost:8080
3) Add localhost:8080 to PhpStorm Preferences => Language and Frameworks => PHP => Servers:
Name: Localhost:8080
Host: localhost
Port: 8080
Debugger: Xdebug
4) Update php.ini:
Php => Interpreter => […] => Configuration file - Open in Editor
Add this section: (check zend_extention path through the cli)
[Xdebug]
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9001 (same as in Debug preferences)
5) Add Debug Configuration:
Run => Edit Configuration => add - Php Web Application
Choose Localhost:8080 server
6) Click Start Listening for Php Debug Connections
7) Set up breakpoints
7) Click on Debug (Green bug)
I'd also be interested in a better solution but I doubt there is one.
xdebug with a frontend like NetBeans, Eclipse or MacGDBp is probably where the bets go.