Posts Tagged ‘getting started with PHP and MAMP’

By Mike Hubbartt, © Copyright 2011, All Rights Reserved.

I like using MAMP (Mac Apache MySQL PHP) to develop server-based code when not connected to a test server, and one of my classes in school had several projects where we use PHP and MySQL, so this short piece is on the basics of configuring and using Eclipse Helios to write the PHP code and MAMP to provide server-side functionality on your computer to create a basic PHP application.

  1. Download and install Eclipse for your development platform from here.
  2. Download and install MAMP (or WAMP if you run Windows, LAMP if you run Linux, and SAMP if you run Solaris). You do not need the Pro version of the software.
  3. Start Eclipse, open any perspective and select the ‘Help/Install New Software’ menu option.
  4. In the popup window, there is a field titled ‘Work with:’ – select the drop down list beside it and choose ‘All Available Sites’. Scroll down the list and expand the options for ‘Programming Languages’.
  5. Scroll down the list and click inside the box for the option labeled ‘PHP Development Tools (PDT) SDK Feature’.
  6. Press the ‘Next’ button twice, select the radio button that indicates you accept the license agreements, then press the ‘Finish’ button.
  7. Restart Eclipse with the ‘File/Restart’ menu option.
  8. Open the Mac OSX Applications folder, and then locate and open the MAMP folder. Your next steps are to start and configure MAMP.
  9. Click one time on the MAMP icon.
  10. Click on the ‘Start Servers’ button.
  11. Click on the ‘Preferences’ button.
  12. Check the value of the ‘Start page URL’ – this is the location to store your HTML, PHP, and image files. You need this when you create a new PHP Project in Eclipse. Press the ‘Cancel’ button.
  13. Open the Mac OSX Applications folder, and then locate and open the Eclipse folder.
  14. Click one time on the Eclipse icon to start Eclipse.
  15. You see the preliminary Welcome screen. To close it, press the close button beside the Welcome tab in the far, upper left area of the screen.
  16. Select the ‘Window/Open Perspective/Other…’ menu option to select the PHP perspective.
  17. Select the ‘File/New/PHP Project’ menu option.
  18. Enter a project name, but this is where you deviate from typical Eclipse project setup. Select the radio button beside ‘Create project at existing location’ and browse to the ‘Start Page URL’ directory (see step 12) and use this as the location for your PHP project.
  19. Select ‘File/New/PHP page’.
  20. For a simple hello world application, enter this code:
  21. Save the file with a name of ‘hello.php’ using Eclipse.
  22. Open your browser and use this as the URL for your simple PHP web page:
    http://localhost:8888/hello.php

NOTE: WAMP users do not need to have the :8888 portion of the URL. They use http://localhost/hello.php.

You should now see Hello World in your browser. Pretty simple to create new PHP applications after you install and configure your environment. The only thing to watch is setting the location for your Eclipse PHP source code so MAMP’s Apache engine knows where to find it.

An excellent source of PHP information is http://www.php.net. They have documentation that can be read online as well as downloaded.

1/21/2012 Update: Added label for radio button in step 18, per comment from Stephen.
11/8/2011 Update: Added sentence to intro paragraph, change hello/php to hello.php in the Note.
3/11/2011 Update: Added WAMP information in the Note below step 22 of this process.