Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 333
ProfK Avatar asked Dec 04 '11 17:12

ProfK


People also ask

How do I debug PHP in Chrome?

Q: How to debug PHP in Chrome? A: You can easily debug PHP in Chrome using a simple extension called PHP Console. Just install this PHP debugging tool from the Chrome web store and start logging errors, warnings, exceptions, and vars dump on your Chrome browser.


2 Answers

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.

like image 91
Álvaro González Avatar answered Oct 22 '22 04:10

Álvaro González


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.

like image 29
PointedEars Avatar answered Oct 22 '22 05:10

PointedEars