Skip to main content

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?


Source: Tips4allCCNA FINAL EXAM

Comments

  1. 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.

    ReplyDelete
  2. 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).

    ReplyDelete
  3. 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.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.