How to set up remote debugging with phpstorm and Xdebug - php

I've seen other questions/answer about this topic but none of them seem to have the same issue I have, so here we go:
What I'm trying
I'm using phpStorm 8 to develop PHP websites (CakePHP 2.5.1 in this specific case). I have a copy of the website on my computer, make whatever changes there and upload the new version to the production server via the integrated FTP tool. So far all pretty simple, no issues at all.
Now I would like to start using Xdebug to debug the websites using the production server (PHP 5.3.28), so I'm trying to set up remote debugging with phpStorm and Xdebug.
What I have done so far
I have installed Xdebug 2.1.3 on the production server, and it seems to be working. To test that I've done whats recommended in this other SO question, and all those things work.
This is how the config in php.ini looks like:
zend_extension="/usr/local/src/xdebug-2.1.0/modules/xdebug.so"
xdebug.profiler_enable='0'
xdebug.profiler_enable_trigger='1'
xdebug.profiler_output_dir='/home/username/debug'
xdebug.remote_enable='1'
xdebug.remote_connect_back ='1'
I'm not setting the remote_port variable because I'm fine with the default port (9000). Also, I'm not setting the remote_host IP because I'm using the remote_connect_back option to allow multiple IPs, as explained here.
I've also tried 2 different approaches to set all this up:
I followed this Zero Configuration tutorial, but at step 7 I never get the Incoming Connection dialog.
I also followed this different tutorial but in the Integrating XDebug with PhpStorm step I don't have the choose XDebug from the Debugger drop-down list option on step 3
What I need
If someone could help me figure out what I'm missing or doing wrong that would be great!

I would have added this to the comments, but don't have the needed rep.
Have you set the preferences correctly in your project? Were you able to configure and validate your deployment server (under Deployment)?
After that, set up the server under PHP > Server and validate it as well.
Don't forget to check the firewall on your host.
Make sure that you can get XDebug working without PHPStorm, then circle back around and integrate it.
These are the php.ini settings, other than the driver path, that I am using for my CLI project:
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_autostart = 1
xdebug.remote_host = 192.168.100.1
Most importantly, listen to LazyOne. Specify your remote host. And don't run debuggers on your production gear. Spend some time learning about Virtual Machines. My recommendation is to check out VirtualBox, Vagrant, and SaltStack. Used together, these tools will allow you to debug your code in an environment that is as close to production as possible without adding the burdens and risks involved with your debugging tools.

Related

How to debugging php on a VPS using phpStorm and Xdebug?

I have trying to get this done for days...and reading through about 20 tutorials, documents, etc...but still no luck.
Here is the thing. I installed wordpress(just for example, can be any php program) on my VPS, and hoping to debug it from my macbook and my desktop. This is clearly a remote debugging thing. So I here is what I done:
1.Installed right version of xdebug and located its .so file on VPS.
2.Changing php.ini and 20-xdebug.ini file on VPS, my settings currently are:
zend_extension=/usr/lib/php5/20131226/xdebug.so
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.remote_port=9200
xdebug.show_local_vars=0
xdebug.var_display_max_data=10000
xdebug.var_display_max_depth=20
xdebug.show_exception_trace=0
xdebug.remote_log=/var/log/xdebug.log
;xdebug.remote_host=202.84.93.66
The last line, which is comment out is my desktop IP address, where I run phpStorm. Based on xdebug's documents, if you set remote_connect_back=1, you won't need this host ip to be specifici.
On phpStorm Side, I "start new project from existing code, and specificy the source root on VPS, map it with one of my local dest. PhpStorm just downloaded all the files and after setting up "Automatic upload", the sync is perfect.
On phpStorm side, I specificy the PHP intercepter as the remote one on my VPS.
On phpStorm side, I changed my debugging port to 9200, as same as the one I using on VPS.
Using the booklet method phpStorm provide, I put them on my firefox bootkmarklet.
Click listen button on phpStorm, set breakpoint, go to firefox open the page, click 'start debuging', refresh.....BUT NOTHING HAPPENS!
I also tried to using the tranditional methods, which set a run configration way as both php-webapplication or php-remote-debug...but still not working.
At php storm, the web debug validation, I could pass all the testing there though....
Can anyone help me with this? I think I must be doing wrong on some very fundation part since I saw all the tutorial are so simple set, but this already took me about 3 days to figure out....
Thanks!

How to debug apis in PHP (without using var_dump();die();)

So I'm writing an api in php, and I'd like to use a full-service debugging tool. i.e., set breakpoints, view stack traces, inspect variables, etc. This kind of thing is very common in compiled languages.
I've checked out xdebug, and after configuring it to work with phpstorm (my IDE), I was disappointed to find that it only works when I run from within phpstorm, not when I actually service real api requests.
To add additional complexity to this, the api dbs are actually hosted on a vagrant instance, so although I write and edit code on my local machine, the code being run is in a virtual machine vagrant environment.
Any other way of doing this? Or should I just get used to something along the lines of print_r();exit; and rerun the request?
Use XDebug, and configure it properly. You can configure it to work without running the code from PhpStorm quite easily.
xdebug.remote_enable = on
xdebug.remote_connect_back = on
xdebug.idekey = "vagrant"
Make sure those are set. Then, in PhpStorm, there is something that looks like a phone icon in the top right (along with the rest of the debugging and running stuff in the toolbar). Make sure that is all green (i.e. listening for connections).
You can use Xdebug to set breakpoints. It'll even work with CLI apps if you've set it up properly. You can even debug code from inside Vagrant VMs, or on remote servers.
You just need to do some research into how to set up your IDE. ;)
More details: http://www.sitepoint.com/install-xdebug-phpstorm-vagrant/
This may come in handy for you: https://www.jetbrains.com/phpstorm/marklets/
And this: https://www.jetbrains.com/phpstorm/help/configuring-xdebug.html
And this: https://confluence.jetbrains.com/display/PhpStorm/Zero-configuration+Web+Application+Debugging+with+Xdebug+and+PhpStorm
Php xdebug
Take a look this example: http://www.sitepoint.com/install-xdebug-phpstorm-vagrant/
best tool available for php debugging is Xdebug. http://xdebug.org/ here is homepage.

How to get Visual Studio Development Server to work with PHP?

I'm a .NET specialist working with a PHP/Flash programmer to deliver an app via IIS. After jumping through 17 hoops of fire and defeating a gargoyle in a gruesome battle to the death, I managed to get my IIS 7.5 server to cooperate with PHP, and now if you browse to my public web site, you can see the Flash objects happily doing their behind-the-scenes stuff with PHP, whatever that may be.
But... when I'm debugging my app using the VS Development Server, that still apparently doesn't know how to cope with PHP: I'm getting the same HTTP 405 (Method Not Allowed) errors that I was getting on IIS before aforementioned gargoyle breathed its last ("The HTTP verb POST used to access path '/php/blah.php' is not allowed.").
So, what do you have to do to get the VS Dev Server to play nice with PHP?
My PHP Debugging Setup
I'm a .NET developer who has been swimming in the PHP pool for the past few months.
Spoiled by the VS.NET IDE, debugger, and strongly typed platforms, I was determined to create a PHP development environment that closely resembles my .NET debugging experience.
NOTE: It may be easy to setup PHP debugging in IIS for new PHP applications. However, the steps listed below break down some very involved steps as I found required to debug in WordPress and Joomla. Only follow these steps if you aren't having any luck with getting debugging to work.
Disclaimer:
The full set of steps to complete this setup are quite involved. I'm throwing this together ad hoc in hopes it will help others in need of setting up a professional development environment with little background in Linux based systems.
These steps are not guaranteed to work and may be very sensitive to environment settings. I spent a lot of time going through the effort of trial and error until I got this working.
Along the way, I have to give credit to a few good online resources you should review to get started. These do not address debugging or development setup. I'll provide details below.
Step by Step Guide: Installing XAMPP and WordPress on Windows
Since I'm new to posting here, I can't add more than one link. Just Google the following references:
- Google: sixrevisions tutorials web-development-tutorials using-xampp-for-local-wordpress-theme-development
Securing Your XAMPP Installation
Google: robsnotebook xampp-builtin-security
DEVELOPMENT SETUP
WAMP Stack vs IIS for PHP:
First, I did not use IIS to host my PHP application. I wanted to keep these web servers separate and use one of the available WAMP Stacks to develop against. This allowed me to manage and study configuration settings that would be used on Apache and Linux. If I was deploying the PHP App to a Windows host, I would have chosen an IIS setup. Again, this was a choice based on creating similar configured environments with a Linux host.
What is WAMP Stack?
For those unfamiliar, a WAMP Stack stands for a distribution package of Apache, MySQL, and PHP running on Windows. Other flavors include LAMP (for Linux), MAMP (for MAC), and others. There are several flavors within the community that provides WAMP Stacks to work with. I originally found BitNami interesting to work with. However, I was not happy with the Control Panel used to manage the different services within the Stack.
Selecting XAMPP for Windows
At the end of the day, I went with a package called XAMPP (Cross Platform Apache, MySQL, PHP, and PERL). The second P in XAMPP provides PERL support that is lacking in the other WAMP Stacks (WAMPServer, bitnami, and a few others). I also like XAMPP because it has what appears to be a more active community and the stack has been very stable for me. Additional standout features of XAMPP to consider is support for hosting an FTP Server, apache based mail server. The option to run MySQL and Apachi as services or local running app is easily toggled with a click of a button.
Setting Up XAMPP for Development
Setup of XAMPP is straight forward. My experience is with the previous release 1.7.3. They just released 1.7.4. Go to:
Google: apachefriends xampp-windows
and scroll down the page till you see the install links. If you want to work with a release that has matured with some time, you can still find 1.7.3 at the following link:
Build Link: www (dot) apachefriends (dot) org (/) download (php) ?xampp-win32-1.7.3.exe
Installing XDebug for PHP Debugging
This applies to installing PHP on WAMP with Apache or on IIS. Selecting the correct version of this dll isn't straight forward.
First, go to:
Google: xdebug org download (php)
and review the various versions available.
The versions are not very intuitive to parse. Follow this guide to understand it:
Breakdown of XDebug Name: [php_xdebug-2.1.0-5.3-vc6.dll]
- XDebug version 2.1.0
- Compatible with PHP 5.3
- VC6: Use for Apache ver 1 or 2
- VC6 indicates compiled with legacy Visual Studio 6 Compiler
- VC9: Use for IIS
- VC9 indicates compiled with Visual Studio 2008.
- NTS (not listed in the name above) indicates Non Thread Safe.
- The version listed is thread safe.
PHP.ini Config Setting
NOTE: Since I've not set this up on IIS, I'm not sure what the specific settings are to apply. However, this is document throughout the web.
For WAMP/XAMPP:
Locate \php\php.ini file.
Comment out line by adding semi colon to start of line.
;zend_extension = "php\ext\php_xdebug.dll"
Locate [XDebug] Section
Use settings similarly listed below and set to your path:
[XDebug]
;Common Settings
zend_extension = "P:[Fully Qualified Path]\xampp\php\ext\php_xdebug-2.1.0-5.3-vc6.dll"
xdebug.profiler_enable = 1;
xdebug.profiler_output_dir = "P:[Fully Qualified Path]\xampp\tmp"
xdebug.profiler_output_name = "xdebug_profile.%p";
xdebug.remote_enable = 1;
xdebug.remote_host = "127.0.0.1";
xdebug.remote_port = 9000;
;Make sure your IDE setup on port 9000. Some will default to 7870.
xdebug.trace_output_dir = "P:[Fully Qualified Path]\xampp\tmp";
;************
;Needed for IDE Support
;************
xdebug.idekey = "vsphp";
;This value can be arbitrary or may require something specific for your IDE.
xdebug.remote_autostart = 1;
xdebug.var_display_max_depth = 5;
Debugging with IDE
I use 2 IDEs to develop in PHP:
phpDesigner7
Google: mpsoftware phpDesigner
VS.PHP (a PHP plugin for VS.NET 2010).
Google: jcxsoftware vsphp
I want to love VS.PHP in VS.NET 2010, however, it's not the greatest experience in step through debugging. phpDesigner7 has been much better for debugging and access to local variables, intellisense, and using running eval commands during debugging. VS.PHP is so close to being great, but you will be frustrated if you have little patience. I still prefer it as my development editor of choice, even for PHP.
Regardless of IDE, most IDEs provide internal debugging support without any of the extra steps I listed above. However, these applications will launch the php app in a private webserver using IDE specific php.ini settings.
I'm doing a lot of custom integration with WordPress, Joomla, and .NET applications. Therefore, I need the debugger to use the php.ini settings for my various platforms. For me to debug these platforms, I configure my IDEs to essentially run in remote debug mode. The IDE and web server coordinate run time execution with the help of XDebug acting as a broker and providing the necessary debugging symbols to the IDE debugger.
Configuring IDE for Debugging
Final step is to configure your IDE so the debugger can connect to the web server.
The 3 settings to look for are as follows:
PHP-CGI: P:[Fully Qualified Path]\xampp\php\php-cgi.exe
PHP.INI: P:[Fully Qualified Path]\xampp\php\php.ini
Listen Port: 9000
Different IDEs may label these settings differently and require additional settings. These should be the most important ones to look for.
NOTE: Use [php\php-cgi.exe], not [php\php.exe] for debugging. The php-cgi.exe is required to run php.exe on windows.
I hope this gets you started with attaching your IDE to the web server, setting breakpoints, and doing a lot with line by line debugging.
You will not be able to make Visual Studio Development Server work for PHP. However you can easily use IIS Express (http://weblogs.asp.net/scottgu/archive/2010/06/28/introducing-iis-express.aspx) which will not only give you PHP, but also install WinCache, URL Rewrite and other features that are super important for PHP development.
Also, note that other platforms like Classic ASP are supported as well, where in Cassini they are not.
One option is to not run cassini and instead just get IIS installed on your dev box and run everything through there.

Configuration parameter in xdebug for allowing multiple hosts on remote machine

I am working on one web application. The project located on my linux box i.e. server.
We are remotely accessing this machine from Windows.
I am using xdebug for debugging along with Eclipse PDT.
xdebug is installed on my server. The below configuration is set in the php.ini file (which is located on the server):
xdebug.remote_enable=1
xdebug.remote_host=10.88.36.1
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
xdebug.remote_log = /tmp/xdebug.log
After doing the above configuration setting in php.ini for xdebug, it's allowing only one host ( i.e. 10.88.36.1)
I want to allow for multiple hosts. I know in zend debugger there is a configuration parameter option which does this i.e.
zend_debugger.allow_hosts=10.88.36.28, 10.88.36.1
Is there an equivalent option for xdebug so that i can able to allow multiple hosts to have access to server remotely?
This discussion suggests using a 'DBGp proxy'. The linked PDF gives a general idea of what to look for. Further research shows only one implementation: Active State DBGp Proxy which is distributed as part of the Komodo package. Configuration is documented here. A slightly older version is available separately.
I'm not sure if this is a perfect solution for your problem but I found that it will accept multiple hosts in this fashion:
xdebug.remote_host=10.88.36.1
xdebug.remote_host=10.88.36.2
xdebug.remote_host=10.88.36.3
xdebug.remote_host=10.88.36.4
Although multiple connections will not be able to debug at once, if a machine is listed here it should be able to connect. Also correct me if I'm wrong but block definitions do NOT work (ex. 10.88.36.0/24) as far as I can tell.
Source: me mucking around

PHP: Profiling code and strict environment ~ Improving my coding

I would like to update my local working environment to be stricter in an effort to improve my code. I know that my code is okay, but as with most things there is always room for improvement.
I use XAMPP on my local machine, for simplicities sake Apache Friends XAMPP (Basic Package) version 1.7.2 So I've updated my php.ini : error_reporting to be E_ALL | E_STRICT to help with the code standard. I've also enabled the XDebug extension zend_extension = "C:\xampp\php\ext\php_xdebug.dll" which seems to be working, having tested some broken code and got the nice standard orange error notice.
However, having read this question, Profiling PHP code and enabled the profiler, I cannot seem to create a cachegrind file.
Many of the guides that I've looked at seem to think you need to install XDebug in XAMPP which leads me to think they are out of date, as XDebug is bundled with XAMPP these days.
So I would appreciate it if anyone can help point me in the right direction with both configuring XDebug to output grind files, and or just a great set of default settings for the XDebug config in XAMPP. Seems there is very little documentation to go on.
If people have tips on integrating these tools with Netbeans, that would be awesomesauce.
I'm happy to get suggestions on other things that I can do to help tighten up my php code, both syntactically and performance wise
Thanks, and apologies for the rambling question(s)!
Ninja edit
I should menion that I'm using named vhosts as my Apache configuration, which I think is why running XDebug on port 9000 isn't working for me. I guess I'd need to edit my vhost to include port 9000
If you always want to run the profiler:
xdebug.profiler_enable = 1
else if you want to selectively switch the profiler on (a good thing), use:
xdebug.profiler_enable_trigger = 1
If you're triggering, you'll need to using the XDEBUG_PROFILE GET/POST parameter, or send a cookie with the name XDEBUG_PROFILE. There are browser add-ons to help; For Firefox I use Xdebug Helper, but as it seems to have disappeared you could try easy Xdebug.
I found that the default output dir didn't work, so try setting it yourself:
xdebug.profiler_output_dir = /home/deebster/php/profiler
Remember to set the directory's permissions to allow Apache to create files if you don't use /tmp

Categories