Why does Xdebug not get my connection, using PhpStorm - php

I can't seem to get my Xdebug to work with PhpStorm.
It works fine for PHPUnit tests, so I'm assuming it's an issue with my local server.
Now for those tests I always have a Configuration for the Test-Class in question (those seem to auto-generate). I do not have one of those prepared for the class I'm currently trying to test (I seem to remember it working at some point and never having an explicit Configuration, but my memory is hazy).
My Debug Configuration:
My CLI-Interpreter (having Xdebug registered):
My xdebug.ini Config:
I'm trying to debug a Magento application running on localhost, port 80.

The issue was that my CLI and Webserver were using different configurations. Thus tests were working fine (using the CLI configuration) but debugging incoming connections did not work (using the Webserver configuration).
The configuration used can be checked via phpinfo() (or php -i for the CLI).
In my case the CLI configuration could be found under /etc/php/{version}/cli and /etc/php/{version}/fpm respectively. Both contained a folder called conf.d in which Symlinks to the desired modules have to be placed (for me they could be found under /etc/php/{version}/mods-available). I added the Symlink for Xdebug in my .../fpm/conf.d configuration and it worked like a charm.
Thanks again for the helpful comments.

Related

Remote Symfony2 + Netbeans workflow (feat. git)

I'm hoping someone have encountered this problem before and will be able to help
So, the problem goes like this: There's 2 developers, each one of them needs 2 versions of a website (development + production). Due to very different operating systems, triple configuration difficulities and administration restrictions on them it's impossible to run projects locally. But there's a bunch of problems while running them remotely:
How to run Symfony2 CLI commands in Netbeans (since those commands need access to db)?
How to differentiate between production/development? I have allowed external access to db for 2 IP addresses, but theres only one parameters.ini file. And once it's used to connect to localhost (when run by http), and second it's used to connect via remote host (when CLI command is run in netbeans)
More info you may ask, so here it goes:
Dev #1: Kubuntu 12.04 x64 3.2.0-25-generic NB#7.1.2
Dev #2: Windows 7 x64 NB#7.1.2
Server: Ubuntu Server 12.04 x64
SQL: PostgreSQL
webserver: Apache2
Our workflow now looks (or at least should look) something like this:
Dev #1 does something locally, but on run changes are being moved to the server so he can check how it went on beta1.sitename.com.
Each change is commited to user branch in git when suitable.
After testing changes are baing merged to master, tested, pulled to a sitename.com, and then tested again.
After this the cycle repeats :)
PS. Valid answer would also be a hint how proper workflow in that kind of situation should be. I've tried already with post-* git handles, and it didn't work really well either...
First of all I would highly recommend trying to solve the development machine issue. There is vagrant which can be used together with chef or puppet (or a specialiced virtual base machine) to move the development environment into a virtual machine executed on the developers pc. This would also solve many issues regarding the remote server.
If this cannot be done, here are some thoughts:
Netbeans commands won't work remotly. Have your developers ssh into the machine and execute their commands their.
I don't get your development/production environment problem. Their should a at least on virtual host with different config/cache/logs for each developer so the configs can be set correctly. The parameters.ini should not be in your git repository (You can handle this by creating a parameters.ini.dist and ignoring the parameters.ini file) so you can have different parameters.
Another interesting thing (presented on the symfony live 2012 Paris) is that you can do SET_ENV SMFONY_PARAMETER_NAME inside your apache vhost and then use %parameter.name% inside your config files (mind the two underscorse). This could be usefull in your case.
There really is no workflow I know of which could handle multiple developers on one machine with different configs and the like. It's just a mess and you either solve your problems with complex scripts which are run everytime something happens or by finding a better solution like virtual machines or different vhosts with different directories on your servers.

Breakpoints not working in Eclipse with XDebug

I have been trying to set up debugging using XDebug in Eclipse for the last few hours without success.
I have the following in my etc/php5/apache2/php.ini file
[XDebug]
xdebug.remote_enable=on
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_autostart=off
zend_extension = /usr/lib/php5/20090626+lfs/xdebug.so
The zend_extensions = /usr/lib...... was given to me by the custom installation instructions on the XDebug site. I followed the setup instructions exactly as they are on that page - http://xdebug.org/wizard.php
But from what I have read typing the command php -m should show XDebug twice, once under PHP modules and once under Zend modules. Well it is showing up under neither for me. So it seems that XDebug is not getting loaded at all?
Anyone any ideas on how to fix this problem and get XDebug working?
You've editted /etc/php5/apache2/php.ini file which is for apache. You'd want to edit /etc/php5/cli/php.ini for the command line interface's options.
If you pass in the phpinfo() from a web site, that PHP has run through Apache of course. And then the wizard will give you settings for the Apache set-up. If you would have passed the phpinfo() output (php -i) from the command line, it would have given you the settings for the CLI.
Something similar happened to me, the first time I setup xdebug in Eclipse it worked just fine, but the next time I tried it, it wasn't stopping at breakpoints. After a lot of research it turned out that I had 2 Eclipse instances running (one for Java and another for Php) and that caused some kind of issues with the debugger.
After closing both instances and starting Eclipse with php workspace first and then Eclipse with java workspace, xdebug worked fine again. My only idea is that debug port was already used when I tried to use it; or something like that.
An other common problem is that you use a router to get through INTERNET and that you had to forward XDEBUG PORT (generaly 9000) on your PC to make XDEBUG working with ECLIPSE.
But your router gives a dynamic IP to your PC and one day your mobile phone connects to the router before your PC and gets the IP address you configuredon you router IP FORWARDING !
The solution getting a static IP from your router. Here is an explanation: http://webologix.com/fr/blog/xdebug-eclipse-fonctionnement-aleatoire.html

PHP define is not working sometimes on some servers

I am working on a PHP web app with another developer. We have 3 total different environments:
Configuration 1: Windows XAMPP, PHP 5.3.5
Configuration 2: Turnkey LAMP, PHP 5.3.X (turnkey-lamp-11.2-lucid-x86) - not sure which ver, running from virtualbox on a mac
Configuration 3: production server, hostgator shared running CentOS, php 5.3.9 fastcgi
Configuration 2 sometimes will not recognize the defines that are handled in our settings.php file which is require_once at the top of any page which uses it. The defines work fine on Configuration 1 and 3 always. There was nothing of interest in the apache logs, other than the errors generated as a result of the define being treated as a string.
I've searched for a while and cannot find anything that describes this issue. Configuration 2 is the other developer, and i do not have access to his machine right now. Looking for suggestions on how to track this issue down. I think we are going to try a new instance of the VM, using an upgraded turnkey-lamp, however i'd really like to root cause this.
Ok, so i figured out what was happening... and as expected, it wasn't PHP or defines. The errors reported were accurrate. We use Eclipse as the IDE, and Subclipse for SVN. Configuration 2 uses a VM running from a mac, and we added a command in eclipse to sync when files are saved. Apparently the syncing only was happening for the main public_html directory, and not our other same-level directory which has the include file with the defines in it. Ultimately, i needed to look at the actual VM to notice it was way out of date on that one file, and was missing the define statement, which results in the error, but Eclipse was showing the HEAD revision from SVN, which is why it was so confusing, but simple.
Lesson: Make sure you plugged in the TV before calling the repairman.

Can I debug PHP files under Eclipse PDT without using Apache?

I have just installed Eclipse PDT 3.0.2 (I don't know what Eclipse base this is, Galileo or Helios), and have been enjoying the step up from NetBeans. In getting more serious about my PHP development (I have recently expanded from only ASP.NET), I decided to move from editing my PHP files directly under my Xampp Apache doc root (htdocs), and have created a workspace under my usual source location, c:\development.
It seems to me, from what I have been able to quickly glean from all the horribly disparate resources on debugging PHP files under PDT, that the files need to be debugged under Apache, and thus copied to htdocs. Is there a local debugging option that doesn't require deployment or a PHP server, and how do I get closer to using this type of debugger?
I know nothing about Eclipse but I have a strong feeling that you simply want to be able to configure more than one site with Apache, so you can work on a private copy of your project while you host a live release in the same computer.
I suggest you have a look at the Name-based Virtual Host Support chapter in the Apache manual. You can create local domain names in your system's hosts file. Additionally, you can use different local IP addresses (127.0.0.1, 127.0.0.2, 127.0.0.3...) or different ports.
You also mention you've been coding ASP.NET in the past. It's worth nothing that PHP runs fine in almost all web servers, including IIS. You don't need to install Apache and I'm pretty sure that Eclipse doesn't care about your server's vendor.
It seems to me […] that the files need to be debugged under Apache, and thus copied to htdocs.
No, you can do what I (and probably thousands of other developers, as the other answers indicate) do:
Leave your development files in your home directory, where they belong, and configure your local Web server so that the DocumentRoot for a name-based virtual host is your development root (or a subdirectory of it).
The minimum Apache configuration would look like so:
<VirtualHost *:80>
ServerName localhost
ServerAlias 127.0.0.1
DocumentRoot C:/development/
<Directory "C:/development">
# helpful if you want to browse your files
Options +Indexes
</Directory>
</VirtualHost>
The line
127.0.0.1 localhost
should be in your hosts file already, so you should not need to make any changes there. (However, if you think you need another hostname alias, just go for it. I have currently defined 3 additional ones for testing purposes.)
The Apache manual and other default Apache resources should still be available then by default (here: http://localhost/manual/ etc.). For example (I am on Debian GNU/Linux here, so I do not know the exact XAMPP paths):
Alias /manual "C:/Program Files/XAMPP/apache/manual/"
<Directory "C:/Program Files/XAMPP/apache/manual/">
Options Indexes FollowSymlinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
AddDefaultCharset off
</Directory>
(It says so – in Linuxese, of course – in my default /etc/apache2/conf.d/apache2-doc.) See the excellent XAMPP documentation for details.
Is there a local debugging option that doesn't require deployment or a PHP server, and how do I get closer to using this type of debugger?
I do not understand that question. There is no "PHP server". There is Zend Server – do you mean that?
If you want to debug PHP scripts for a Web server like Apache, you need to run PHP on that server. In the case of Apache, either as an Apache module, as a CGI handler, or under FastCGI. You only do not need a server if you are developing CLI-PHP scripts. The XAMPP installer should have set that up for you already.
Assuming from your posting that you want to debug PHP scripts that should run on Apache with the PHP module (run a PHP script with <?php phpinfo(); to be sure; I just do not have active PHP debugging experience with anything else), you can configure PDT so that it uses Remote Debugging with the above local virtual host. For that, you also need a server-side debug module for PHP, for example Xdebug or Zend Debugger (the debug clients for both are included in PDT). I had been using Zend Debugger before, but now I am using Xdebug (with PDT 3.0.0v20110516-… in Eclipse 3.7.1 ["Indigo" SR1, released September 2011]¹) because it is free software, packaged with Debian, and highly configurable and capable even though it is for free as well.
This article helped me in particular: PHP remote debugging with Xdebug and Eclipse PDT.
See the Xdebug documentation for more (e. g., independence of client IP addresses).
However, a wealth of information about PDT and debugging with PDT can be found at the PDT Downloads site.
Bottom line: If you are debugging on localhost, you do not have to deploy your code because you have deployed your code already, just by having it in or below the DocumentRoot. Eclipse PDT does not care where the remote code is located; it only accesses a resource via an HTTP URI. If that starts with http://localhost/, so be it :)
(Copying the resources around carries with it the risk of inconsistencies and accidentally overwriting Apache files, so do not do that.)
¹ There is no PHP package for Eclipse Indigo, but you can start e. g. with Eclipse 3.7.1 Classic and install PDT on top of it using the Update Manager. Just select the "Indigo" (or whatever) repository, then "PHP Development Tools" under "Programming Languages". Dependencies should be resolved automatically. See also PDT/Installation.
I don't remember if Eclipse has a local PHP debugging option or not. But I think Zend Studio (which is based on Eclipse PDT) comes with its own PHP binaries. I've never tried to use them though.
Your best bet is to create a new workspace, which I explained how to do here: publishing php files from eclipse to apache htdocs
If you need to setup vhosts (Virtual Hosts) on your XAMPP installation, this is a great and easy to understand tutorial.
If you want suggestions to alternative IDEs then I would go with Zend Studio ($299) or Rapid PHP 2011. While I've never used Rapid PHP 2011, it does look somewhat promising, has many of the same features as many popular IDEs including debugging. Note that in my opinion, it appears to be not quite as professional as Eclipse/Zend (which, again, is why I always recommend those two above others).
I assumed the question was more about 'can I debug in PDT a CLI script'. If that's the case then, yes, you can.
All you have to do is edit the PHP.INI file that your CLI is using and make sure that XDebug is enabled for the CLI and that xdebug.remote_autostart is set to 1. It's quite possible that the CLI PHP is using a different INI file from Apache, so be sure that you're using the correct one.
Finally, in PDT click 'Debug Project' and debug it as a web script, even if it isn't. The important thing is that you essentially are telling PDT to start listening. Once that's done, you should be able to run the script from the CLI and have PDT kick in at the appropriate time. The xdebug.remote_autostart is key, though.

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

Categories