PHP development in Eclipse

Note:  For anyone who has found my blog from web searching, please be advised that these directions are not complete, they are just my scratch notes as I am trying to figure out the process myself.  However, when I do figure it out, the final notes will be placed on the page you're looking at!

Although PHP is NOT my preferred language for web application development, sometimes you just gotta.

I already have Eclipse and I use it mostly for Java.  However, here's how I installed PHP development tools.

In Eclipse, go to Help --> Install New Software --> click "Add" to add a new site,  for the name I just put "php dev tools" and for the site I put http://download.eclipse.org/tools/pdt/updates/release.   Here's where I got that URL from: http://www.eclipse.org/pdt/downloads/    I think that PDT stands for PHP Development Tools.

Now you can go New --> Project --> Other and "PHP project" will be an option.

Then it will ask you if you would like to switch to the PHP perspective.

Now you can right-click on your new project and go New --> PHP File, say "helloworld.php".

 At this point, you might be inclined to read the PDT User Guide, like me, only to find that the sections, "Preparing the Workbench", and "Creating your first PHP project" are blank.  What the hell!

Well, PHP, perhaps you and I will always have a troubled relationship.  But I will keep trying and I hope that can hold up on your end of things.

Moving on, I'll figure this out for myself.

Right-click on helloworld.php and choose Run As --> ah, ha! there is a new "PHP Web Application" option!  But it doesn't work:  "Page load failed with error: Could not connect to the server."

That's because we haven't created the server yet.  So, let's go into Window --> Show View --> Other --> Servers.   Then right-click in this view and choose New --> Server, then under Basic, choose "HTTP Server".    For "Publishing Directory", Browse to your "htdocs" folder of the Apache installation on your machine, then go into the web folder for this specific project.  I have a Mac, which comes with Apache installed by default.  My user's folder is in /Users/myuser/Sites.  Here's a handy link for setting up Apache + PHP on OSX Mavericks: http://akrabat.com/computing/setting-up-php-mysql-on-os-x-mavericks/.

Anyway, back in Eclipse type in the location where the PHP files should go where Apache can see them.  Click through the rest to finish setting up the server.

NOW you can right-click on helloworld.php again and Run As PHP Web Application.  This time, you see a familliar Apache Not Found message.   Next we gotta set up so the PHP files are automatically copied from Eclipse into the htdocs folder......... and so far I have failed to get this working.  So I will just manually copy the php files from the Eclipse workspace into the Apache htdocs folder for now.  So annoying!  I thought I could create a symbolic link from the workspace to the htdocs folder, but PHP files give me a 403 Forbidden.  I made the "real" files in the workspace and the symbolic link in the htdocsfolder.  Maybe I should try it the other way around.

Another thing you can do is right-click the PHP project --> Properties, then go under "Targetted Runtimes".  This will take you to a screen similar to above (where you have to put in "HTTP Server" and "Publishing Directory".  When I tried this the option I had set up above was greyed out.  I don't know why.

When doing this, you will likely set up a whole bunch of Servers, most of which you won't need.  How do you delete the extra ones?  Find the Server tab in Eclipse, right click and pretend you're going to make a "New" server.  In that window you'll get a link "Configure runtime environments" where you can remove the extras.

Eclipse / PHP links:

  • Installation on Eclipse: http://robsnotebook.com/php_debugger_pdt_xdebug
  • http://www.eclipse.org/pdt/help/html/running_php_web_pages.htm
  • http://stackoverflow.com/questions/432162/does-anybody-have-a-development-staging-deploying-workflow-with-php-mysql (team workflow)
  • http://ubuntuforums.org/showthread.php?t=1787976 (note to self, read this one again - bottom!)
  • http://coolestguidesontheplanet.com/install-configure-apache-mysql-php-phpmyadmin-osx-10-8-mountain-lion/
  • http://brianflove.com/2013/10/23/os-x-mavericks-and-apache/
  • Symbolic links discussion http://stackoverflow.com/questions/4097946/whats-the-best-way-to-deploy-a-php-pdt-eclipse-project-to-apache-on-ubuntu
  • OS X adding a user to a group (to give Apache user permission over the folder containing PHP files)  http://superuser.com/questions/214004/how-to-add-user-to-a-group-from-mac-os-x-command-line
  • NETBEANS PHP https://netbeans.org/kb/docs/php/project-setup.html#localServer


JUnit testing

After many years of "I've been meaning to try this!" but never actually having time to do so, I finally incorporated my first JUnit test into a codebase.

In Eclipse, I right-clicked on the package containing the class I wished to write tests, for, then I chose New --> Other --> JUnit Test Case, click Next, then create a class name (ex. MyClassTest) then finish.

Next, write your test methods.

Next, right click on the new class in the Project Explorer, then choose Debug As -> JUnit Test.  (I originally goofed up here because I picked Run As --> JUnit Test.  But when I did that, the variable inspection features didn't work!)

Next, the perspective will change to Debug, then you can click the items in the Variable column to view the contents, set break points, etc..

This is my favourite part about my job!  Too bad it's so rare I get to do this, hahah!

Eclipse / JUnit links
  • http://courses.cs.washington.edu/courses/cse143/11wi/eclipse-tutorial/junit.shtml 

TOOC

Ever heard of a MOOC? We'll, I'm in a TOOC! (Truly open online course, because unlike most MOOCs, you can continue to access course content and connect with peers, even after the official end of the course.  That, and the content isn't locked down behind some system that requires an account to log in.  At least, that's my personal understanding.)

As part of this TOOC, I am writing about why I decided to participate.  The first reason is that the instructor is a colleague of mine and filling in the sign up form was one way I wanted to show support and encouragement for this endeavor.  The second reason is that I was aware several other colleagues had signed up, and I wanted to take the opportunity, if I could, to connect with them on a topic of mutual interest. Third, maybe I will learn something new!

As part of this TOOC, I am also writing about why keep this blog. I have been blogging for about 8 years and I still love it.  It's like having a conversation with myself while allowing the entire world to listen in, and discovering how it's possible to connect with someone else on even the most arcane or subtle idea. I love reading other people's blogs for the same reason.  A blog is a place where you can store a half baked idea or neat link that you've stumbled upon and elaborate your thoughts on it later (by creating a new post and linking back to the first one for reference to the earlier version of the idea.). I learned that before I started blogging much myself, from Darren Cannell, author of Teaching and Developing Online.

Hello, TOOC world!

Translate