Develop PHP Code with Eclipse and MAMP (January 21, 2012)

Posted: February 25, 2011 by Mike Hubbartt in Academia, Development, Tips and Tricks
Tags: , , , ,

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.

Advertisements
Comments
  1. Melita Raks says:

    Thanks!

  2. swydell says:

    I just want to say thanks. I’m a beginner, learning php. Up until I came across this site I could not figure out how to use eclipse. I have MAMP installed. Now I can go about practicing php code in eclipse, thanks to you.

  3. Stephen says:

    This was a very helpful post, thanks very much.

    One brief suggestion…step 18 “Select the radio button” was a touch vague, there were three buttons on my screen at that stage, perhaps because I had already downloaded eclipse for Java. I wasn’t sure if I had done things right until a ran the test and the page actually displayed. Anyway, thanks again for your help, much appreciated.

  4. nurah says:

    after three days of trying different tutorials and configurations… it worked out through your lesson!
    thank you so much!

    • Nurah:

      Glad my article helped you. When I first started working with PHP, I ran into the same issue you did. I couldn’t find many good setup examples. That was the reason I started posting them here – to help others learn new technologies using familiar tools like Eclipse and MAMP.

      Mike

  5. John says:

    Thank you for this article. Eclipse can be very difficult to configure and you made it simple for me.

    Since you have more skill than I (smile), might you consider articles on using frameworks such as Yii in the Eclipse / MAMP environment? I would also like to configure Python/Django inside a MAMP environment.

    I hope you will consider these.

    Again, THANKS!

    -John

  6. David says:

    Regarding when you use Eclipse Indigo/PDT with Mamp: The run configurations(RC) are really a PITA.
    If you use a workspace folder other than the root htdocs it does not auto generate the complete path in the RC and it does not let you add it either. It tells you file does not exist! This means you have to put all projects at root of htdocs with all metadata etc. What a PITA. I have spent days trying to figure what I am doing wrong. Eclipse is probably just too much configuring for newbies! And I am not necessarily a newbie.
    Is there a workaround? I really don’t want everything piled up in root htdocs.

    • David:

      I understand and agree that using htdocs as a home dir for server-based development seems like a PITA, I don’t know of a workaround.

      I view it as similar to using a different drive location than the default IDE directory for a repository, so I just accept it as the price of using MAMP or WAMP.

      Don’t give up on it as it does a reasonable of providing server-based web development when you lack access to a test server. You might want to look at Amazon Web Services (AWS) as it provides a free Linux or Windows server for 1 yr, but be aware Amazon will start billing if you go past the free service time.

  7. jose says:

    Works like a charm! Only a quick note: in my case, (in MAMP app) the URL is not the one that says “Start page url” in Start/stop tab, but the “Documents root” in Apache tab. In my case, the first one is “/MAMP” while the second one is “/Applications/MAMP/htdoc” (the correct one).

    And… A quick tip. I didn’t like to have projects “everywhere”, I prefer to have all in one place. So, what I did is create the project in the workspace as usually, and then, create a link in the htdoc folder to that project ($ ln -s /Users/myUser/pathToMyWorkspace/myProject /Applications/MAMP/htdocs/myProject). This, of course, thanks to the power of Unix :D. In windows, I am afraid it’s not that simple.

    Cheers!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s