Page 2 of 2
Now that you have Eclipse installed and working it's time to write a first PHP program.
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.
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.
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.
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';
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
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.
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.
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.
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 [ ... ]
PHP Inner Functions And Closure
PHP inner functions and anonymous functions are a little strange to say the least. However, just because something is strange doesn't mean that it isn't useful. We take a close look at the way PHP fun [ ... ]