Beginning PHP with Eclipse
Monday, 16 November 2009
Article Index
Beginning PHP with Eclipse
Hello World

Hello world

Now that you have Eclipse installed and working it's time to write a first PHP program.

Banner

Start Eclipse and when it asks you to select a Workspace browse to \xampp\htdocs or to the htdocs folder where you installed XAMP. You can opt to set up a Workspace anywhere but the simplest option is to place it within the folder structure of the web server. The reason is that when you come to run your PHP program Eclipse will generate a URL and expect the web server to find the file and serve it to the browser. This is most easily achieved by storing the Workspace files below the web server's root folder - often called www or Inetpub in the case of other installations.

fig4

Set the workspace

Once you have set up the default Workspace you will see the Eclipse Welcome screen.

The tutorials and other pages on offer are not very helpful to the PHP programmer so your best option is to click on the Workbench icon which is unhelpfully well over to the right.

fig5

The Workbench icon is on the far right

The Workbench is where you will do most of your coding and even testing so it is worth getting to know.

Initally you will be looking at a blank Workspace ready for you to create a project. Use File, New, PHP project and call the project Learn PHP - you can leave all of the defaults as they are and click the Finish button.

fig6

Create a new PHP project

A project is a container for possibly a complete website and certainly more than one PHP file. So our next task is to create a PHP file. Use the File,New, PHP File command and name the file Hello1.php and again accept all of the defaults by clicking on the Finish button.

The PHP page that appears in the editor already contains a single line of PHP <?php. To this add the command

echo 'Hello PHP World';

fig7

The PHP program ready to run

Next save the file - if you don't you will be prompted to do so before the program is run. To run the program select Run, Run As, PHP Web page. You will be prompted to OK the launch URL which should be

http://localhost/Learn PHP/Hello.php

This is the URL that you would type into a browser to see the page just created. While PHP is a programming language it is deeply mixed up with web pages and browsing and running a PHP program really means loading it into a browser.

fig8

The URL to the PHP page to be run

As long as everything is OK you should see the output of the program in another tab that opens in the editor and of course this should say "Hello PHP World". This is in fact the Eclipse default web browser and you can use it as such if you really want to - click the Refresh button or enter another URL into the address bar, say.

fig9

The output of the simple program

As long as you verified that XAMP - Apache at the minimum was installed correctly there really isn't much scope for it all going wrong. The only real possibility is that the URL used to load the program is incorrect and this can only happen if the Workbench has been stored in the wrong place. Make sure that the workbench is stored in the web server's root directory.


That’s all there is to it and now you can concentrate on learning PHP rather than installing servers and software. If you are a beginner to programming now read the first part of our tutorial on PHP.

More PHP

Banner


Developing with PHP and Eclipse (Indigo)

Find out how to make PHP development easy with the latest version of Eclipse, Indigo, and how to set up local and remote debugging.



Object-oriented HTML Generation In PHP

PHP is a programming language specifically designed to generate HTML pages but one of the topics that is rarely discussed is exactly how to do this. In this article the idea that HTML generation shoul [ ... ]


Other Articles

    <ASIN:0470391146>

    <ASIN:0672328887>

    <ASIN:1932394753>



    Last Updated ( Monday, 15 February 2010 )
     
     

       
    RSS feed of all content
    I Programmer - full contents
    Copyright © 2014 i-programmer.info. All Rights Reserved.
    Joomla! is Free Software released under the GNU/GPL License.