Eclipse and PHP

6 downloads 32 Views 706KB Size Report
In order to debug from eclipse, you will need to modify your php.ini file. Go to E:\ xampp\php and find php.ini. I recommend renaming this file to backupphp.ini ...
Go to: http://www.eclipse.org/pdt/downloads/

Click on Download All-In-One Package

On the next site, click on the zipped filed link.

Unzip the file to your portable apps folder.

In order to debug from eclipse, you will need to modify your php.ini file. Go to E:\xampp\php and find php.ini. I recommend renaming this file to backupphp.ini in-case you make a mistake. After you rename the file, open the file. Do a file save as and save as php.ini, and click yes to overwrite the file if prompted. Go to line 2078. You should see:

Clear out everything except [XDebug] and paste this below it: zend_extension = "\xampp\php\ext\php_xdebug.dll" xdebug.profiler_append = 0 xdebug.profiler_enable = 1 xdebug.profiler_enable_trigger = 0 xdebug.profiler_output_dir = "\xampp\tmp" xdebug.profiler_output_name = "cachegrind.out.%t-%s" xdebug.remote_enable = on

xdebug.remote_handler = "dbgp" xdebug.remote_host = "127.0.0.1" xdebug.remote_port = 9000 xdebug.trace_output_dir = "\xampp\tmp"

If done successfully, the text won’t be commented out and should look like this:

Save your changes and close. If you were running apace, you will need to restart it. Go to your portable apps. You should see eclipse. If you don’t, restart portable apps. Click on Eclipse.

When eclipse launches for the first time you will get prompted for a workspace. I recommend setting the workspace to your xampp\htdocs folder. This makes it easier for setting the debugging settings you will set in a few steps. Check the check box and click ok.

A new folder called .metadata is created in htdocs. Don’t delete it, because this folder will store all of your settings.

To create a php project, go to file, new, php project. For project name, enter the name. If you already have a php project, still use the new option. Make sure you name the project the same name as your folder structure. You will notice the directory path change. Since I already have a folder structure as htdocs\assignments I get a message at the bottom of the screen. This is just stating it will import all existing files into this project. I recommend checking Enable Javascript support for this project. You can click Finish because the next steps don’t have any relevance to what we are doing.

If you are in the folder directory, you will notice a new folder called .settings and two files called .buildpath, and .project in the folder. Don’t delete these files.

You will notice in the upperleft corner the name of your project(folder) and whatever was in the folder structure.

The next step is very important. To setup the debug settings, go to Window and select preferences.

Expand PHP, and select debug. Change PHP Debugger from Zend Debugger to XDebug. I also recommend unchecking Break at First Line. If you don’t uncheck this, each time you want to debug, a break will happen on any file that is accessed even if there is no break on the page. This can get annoying when the controller needs to require all the models. Click Ok.

To view a file, go into your folder structure and double click on a file. In the example, I opened index.php.

To debug, you can set a breakpoint by double clicking on the line. You will notice a blue dot. To turn off, double click it again.

To debug, you click on the bug icon on the menu bar. (MAKE SURE APACHE IS RUNNING)

When the page is launched for the first time you will see this popup. DON’T CHANGE THE URL unless you named the project something else and didn’t keep the same name as your folder structure. If you did you will have to adjust the url.

If a breakpoint was set, you should get this message. Check the checkbox and click yes. This says it will open the debugger window.

You will be switched to a debugger tab. You will notice that the debugger stopped at my breakpoint. To step through the code you can use the parts I circled or, Using the following keys. F5 will step into so if you are on a function, include, or require line and press that, you will go to the file or function. F6 will step over the line you so you don’t go into the file or function. F8 will finish processing everything, unless you have another breakpoint that will touched.

Once everything loads, the internal web browser has a url. You can take that url and put it in any browser. You can then launch the debugger from the browser for the current debug session and you click stop on the debug window.

To view what your variables are doing, you can hover then a tooltip is displayed, you will also notice in the upper right hand all of your variables are displayed. As you step through your code you can see the values change.

To stop debugging, click on stop and switch back to the php tab.