PHPStorm CLI debugging on Vagrant instance - php

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

Related

PhpStorm configure Xdebug with Docker

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?

Eclipse Aptana Studio 3, xdebug configuration for Windows with virtual machine

I have a problem to debug php files with Aptana Studio. I don't know is it possible to be done because the way of working is a little bit complicated.
Actually I have my source PHP files into my local Windows machine, also my Aptana studio. The Apache server has been installed on the Ubuntu virtual machine and has as source the files of my local Windows machine.
From the web browser into my local Windows I charge the URL of the virtual machine and I would like to debug from Eclipse/Aptana.
I have to configure Xdebug in Eclipse, but I don't find issues how to do in my case.
Is there someone having the same problem or idea ?
Finaly we found the solution for Eclipse PDT but the same is valid for Aptana just the eclipse configurations are a little bit different.
In order to implements the remote debug you must to install the xdebug packages where the virtual machine is (in our case the Ubuntu virtual machine).
After into the /etc/php/7.0/mods-available/xdebug.ini you must to configure the 2 lines :
xdebug.remote_enable=on
xdebug.remote_host=192.X.XX
where the remote_host is the IP of your local machine containg the eclipse.
Further you must to change the eclipse configuration Windows->Preference->PHP->Debug->Debuggers->Xdebug to put the debug port (same as in xdebug.ini file - default 9000), and set Accept remote session (JIT) to any.
For Aptana change the xdebug configuration by searching where Accept remote session (JIT) is.

Debug PHP cli application inside docker with PhpStorm

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>"

php debugging on a Mac?

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.

debugging php on mac?

was wondering what was the best way to debug PHP on my local machine. I use MAMP on mac os 10.5
thanks,
Patrick
Using xdebug is a good start. Download the package and follow the instructions in the INSTALL file. It's fairly easy. Once this is done, add the following lines to your php.ini file:
;;[xdebug]
zend_extension="/Path/to/your/module/xdebug.so"
xdebug.file_link_format="txmt://open?url=file://%f&line=%1"
xdebug.var_display_max_depth = 20
Don't forget to restart Apache after this.
Most debugging can be done using a simple die(var_dump($some_variable)). It's not very sophisticated, but with xdebug installed, the output of a vardump looks pretty good in a browser. In most of the cases this is enough.
If you need more control, you can add an xdebug_break(); statement in your code and add the following lines to your php.ini:
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
Again, don't forget to restart Apache.
Now, using a tool like MacGDBp (or Eclipse+PDT if you must), you get a classic debugger. You can step though your program.
Have fun!
I've always thought the "best" way of PHP debugging on any platform is by using FirePHP, which can output debug messages straight into the Firebug window in Firefox.
I've found that running php -l myfile.php is great at catching syntax errors before I try and reload the page in my browser (and thus prevent the abominable White Screen of Death). Beyond that, I just point my browser to my local webserver and try to access the pages.
You can do some nifty things in your code itself (like using debug_backtrace()), but that (obviously) requires you to put it in the code yourself.
Personally, I use Eclipse+PDT and XDebug. To simplify things, get Eclipse for PHP Developers from the Eclipse download page rather than installing PDT as a plugin. Eclipse has a high learning curve, but it gives you all the debugger functionality you expect: instruction stepping, breakpoints, watches, even altering variables live.
If you don't like Eclipse or find it's too much for you, there are other clients compatible with XDebug.
I also use eclipse+pdt and xdebug. If you're new to trying out debuggers you can try zend studio which will setup things pretty easily.
Zend Studio is by far the best tool to use to create and debug PHP code. I run the community Edition of Zend Server on my dev Linux box and locally in a virtual machine on my MacBook Pro.
Take a look at the Zend website for details - it has cut my app development by two thirds!
Thanks to a bunch of links like this one and others, here's a compiled solutions that successfully uses OSX's native Apache2 and XDebug together with MacGDBp and a Safari extension called XDebug Helper.
You can do it even without MAMP.
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)

Categories