Setting up a PHP Development Environment – Part 1


Introduction

 Note that this was published back in 2013 and is obsolete. I plan on doing a more modern development environment tutorial at a later date. Images are missing from this entry.

I’m going to show you how to set up a fully featured development environment for PHP5 on Windows (I’m using 7) It will use Eclipse Juno, with The Uniform Server as your WAMP stack. I’m going to break this into a few parts, but you will end up with a full working local development environment with PEAR, XDEBUG, PHPUnit2, Git, phpDocumentor2 and DStruct Framework. What bits you set up or use is obviously your choice.

I want to start with quickly discussing the whats and whys. I’ve been developing for a long time and for many years used the excellent Notepad++ with XAMPP and our company’s internal SVN / Track server with TortoiseSVN. It all worked well, but the opportunity to change came up, and I thought I’d try something different. It was a bit of work getting everything up and running, but I think it is worth it – I now have code-completion, easy debugging, unit testing, easy documentation and more. I used to use XAMPP, but prefer The Uniform Server. I’ve just had less trouble with it and I like the GUI included, especially for PEAR modules. All the other tutorials I’ve come across are incomplete – only covering one part of setting up your environment, but I want to cover it all. That means an environment which is for multiple projects, uses UTF-8 from the browser to the database and back again, includes all the tools developers use on a daily basis etc. Also, there are so many old projects out there which have been superseded or abandoned that I had problems finding out which tutorials I should actually follow.

I should also add that much of this was learnt from elsewhere. I’ll try to reference the original sources where I used them, but I apologise if I’ve missed any out / forgotten where I found stuff.

Ok… on with the show. I’m going to run through this quite quickly, rather than going through every mouse click, but if it’s not clear and you have any questions, leave me a message and I’ll look at updating things.

1. Install Eclipse and start a new Project

Download and install Eclipse. The Standard version should be fine. You’ll need Java installed and will get an error message if you try to start Eclipse without it. You don’t need to separately install Git in Eclipse as everything you need is included (eGit).

Create a folder where you will start your projects. This will not be where our projects end up, as we will move them when we add them to source control.

Start Eclipse and use the folder you just created as your Workspace when prompted.

Go to File –> Install New Software… and click Add. Call it PDT (short for PHP Development Tools) and use the URL: http://download.eclipse.org/tools/pdt/updates/release Install PDT.

Add PDT Repository
Create a new PHP Project in Eclipse. Make sure
you click ‘Create new project in workspace’.

Click Project –> Properties and change the text file encoding to UTF-8. If you want, also change the new text file line delimiter setting.

2. Add your Project to Git

I’ll be going through the absolute basics to set up a project on Git, but I highly recommend you familiarise yourself with this tutorial http://www.vogella.com/articles/EGit/article.html which covers most eGit functionality.
Right click on your project and choose Team –> Share Project.
Select ‘Git’.
Untick ‘Use or create repository in parent folder of project’.
Click the ‘Create…’ button and choose a folder to contain your repo (don’t use a space in the folder name if possible).
Create Git Repo
Back on the ‘Configure Git Repository’ page, leave the ‘Path within repository’ blank.
Configuring new Git repo
Finish, and in the Project Explorer your project should now have the name you gave it in square parenthesis and something like ‘NO-HEAD’.
Add some files to your project if you wish (empty folders can not be added to Git), and when you’re ready, submit your first commit to the repo… I’ve opened the ‘Git Staging’ tab in the ‘View’ pane at the bottom of Eclipse. Drag the unstaged files into the staged area, add a message and commit.

Making initial Git commit
Initial Git commit

3. Install and set up The Uniform Server

Download The Uniform Server and install it in c:\. Do not use any spaces in the installation folder name. If you do so, it will lead to permissions issues and other problems.
Start the Uniform Server Service GUI and use the Server Configuration to set up Apache vhosts. Instead of your domain name “www.example.com”, use something like “www.example.local”. We’ll use the local hosts file later on to point the
DNS. On the version I have installed, the DocumentRoot does not get wrapped in double quotes. This can mean the server won’t start if there are spaces in the path, so you may need to manually edit the file. On my installatin, Apache vhosts is here:
C:\UniServer\usr\local\apache2\conf\extra\httpd-vhosts.conf
Install and start the Apache and MySQL services. Remember to set a root password on MySQL.

The Uniform Server Interface
The services have been installed and started.


Go to Server Configuration –> PHP and choose ‘Install PEAR’. You can go ahead and add any PEAR modules you want, but don’t install PHPUnit – it’s an old version. I’ll go through adding PHPUnit2 in a later tutorial.

4. Set up DNS in hosts file

The local computer needs to know where to find “www.example.com” and so we need to set up the local hosts file which is your PC’s first port of call when resolving an address. I recommend using Notepad++ to edit this file. Although
To open the hosts file, run your text editor of choice as Administrator and use File –> Open and paste in:
%Windir%\System32\drivers\etc\hosts
All the text in the hosts file will probably be commented out. Append the domain name you set up in Apache vhosts to a new line at the bottom of the file:
127.0.0.1    www.example.local

5. Add PEAR to your project

Next, we need to link PEAR into Eclipse.
Right click on your project in the Eclipse PHP Explorer. Click ‘Properties’ and then select ‘PHP Include Path’, then the ‘Libraries’ tab.
Click the ‘Add Library…’ button, then ‘Next >’ to select ‘User Library’.
On the next page, click ‘Configure…’ and then ‘New…’.
Call the new library ‘PEAR’ and tick the ‘Add to environment’ box, then ‘OK’.
Select the library you just created and click ‘Add External folder…’, then select the folder which contains PEAR. On my installation, it is:
C:/UniServer/home/us_pear/pear
It should end up as shown below. In future, you don’t need to create the library, just select the ‘Libraries’ tab when setting up a new project and tick the PEAR library.

Adding PEAR to Eclipse
Your set up should look similar. Note the stack of windows leading to the PHP Libraries one.

5. Conclusion

You should now be able to open your ‘local’ domain in a web browser. Any changes you make in Eclipse should be visible by just refreshing the page.
Part 2 covers adding PHPUnit2.


Leave a Reply

Your email address will not be published. Required fields are marked *