Wednesday, 25 January 2012

Setting up Eclipse check list (Part 5) - PHP development

By this point you will have most of what you need set up.
This post deals with PHP development.
First make sure you have PHP set up.

Follow the steps the professionals give you or my short hand a good PDF is located here or even this one.
  1. Install the PHP Development tools in eclipse.
    This is done under Eclipse-->Help-->Install New Software...;
    Select from the Work with drop down "Indigo - http://download.eclipse.org/releases/indigo"
    then enter PHP in the "filter with type", which should give you the PDT tools as follows:

    #1 Install the PHP Development tools in eclipse.
    Make sure you get a version above PDT 2.2 as it is very buggy.
  2. You may also need these extra bits (I didn't).
     
  3. At this point you have a PHP Perspective in eclipse but the IDE is not set up.
    Running a PHP file will give this error:
  4. So next you need to set up a few PHP settings under Eclipse-->Window-->Preferences; PHP -->Path Variables add  PHP-HOME which points to your PHP instalation (mine is C:/development/php/php_5.3.9) which was set up earlier.
  5. Next create a PHP executable environment under the PHP preferences.
    In mine I called it php-5.3.9 and set the executable path to "C:\development\php\php_5.3.9\php.exe". Also set up the path to the PHP.ini file.
    Within the same window set up the PHP Debugger as XDebug and the type as CGI.
    Mine was called PHP-5-3-9 (XDEBUG) and is defined as the workspace default.
  6. You should now be able to set up a PHP project and create a PHP file to dump the info.
    Some thing like this:
    <?php phpinfo();?>
    Select the php file and perform a (rightclick)-->Run As..-->PHP Script, the result should be largely the same as the output from php -i.
  7. Now lets attempt to do some debugging;
    Enter this script into a file called list.php:

    <?php
    $brush_price = 5;

    echo "Quantity\tPrice";
    for ( $counter = 10; $counter <= 100; $counter += 10) {
        echo "\n";
        echo $counter;
        echo "\t\t";
        echo $brush_price * $counter;
    }
    echo "\n";


    Running it should give a two column result ... easy.
    Now try to debug it (rightclick)-->Debug As..-->PHP Script.
    This should give the same result, so put a break point on one of the echo commands.
    This will give you the eclipse dialog box asking wheter you should open the debug perspective.
    Say yes then happy debugging.
    If nothing happens then you have probably not got the correct version of PHP setup.

The next objective is to get the PHP running in Tomcat and break points set up.



<<Back  | Next>>

No comments:

Post a Comment