
We recommend using Eclipse Indigo with the PHP plugin PDT as your PHP IDE(Integrated Development Environment). Eclipse is a very strong development IDE and has all the features you require, especially debugging. If you are not familiar with debugging we strongly recommend you get to know it. At last it is Open Source.
This guide shows how to install and setup a local PHP development environment using the new version Eclipse Indigo 3.7, Linux Apache MySQL & PHP (LAMP) and Xdebug (debugging feature) on either Linux Ubuntu 10.04 or 11.04. This is a complete guide to setup a local development environment.
We recommend to have a look at VMs If you are in one or more of the following categories:
- Changing computers and want to keep your development environment setup
- Want to use your development environment setup on other computers
- Like to have a separate development environments for different projects and different platforms
Use Virtualmachine?
We recommend using VirtualBox. VirtualBox is a virtualization software which enables you to run a another operation system within the main one. This means that you can create an enhanced development environment and save it to a file which you can start and move to another host PC. This is also Open Source and therefore free. Here is a review of VirtualBox with points on how to install it: VirtualBox the fast and free Open Source Virtualization Platform [Best Free Virtualization Choice]
Install Linux Apache Web Server, MySQL PHP (LAMP)
Open the bash and write the following command. This will install Apache Web Server, MySQL and PHP in one go.
- You will be asked if you like to install, write “y” and click enter.
- Enter a password for MySQL root user, repeat it and you are up and running.
Install recommended Apache Mods
We would recommend installing cURL and rewrite. cURL is a tool for transfering data to the Server and rewrite enables nice URLs. These mods are used in most common CMSs like Drupal, WordPress and Joomla. Installation is done by following commands in the bash:
sudo a2enmod rewrite
Install PHPMyAdmin
PHPMyAdmin handles the administration of your MySQL databases over the web. You want this.
To install it write the following in the bash:
Under the installation choose the following:
- Choose Apache2
- Configure database for phpmyadmin with dbconfig-common? > Yes
- Supply your MySQL password
- Choose PHPMyAdmin password.
Test PHPMyAdmin on this address: http://localhost/phpmyadmin
Use Virtual Hosts
We recommend using the virtual host mod vhost_alias for Apache. This enables you to run more than one web site (such as www.domain1.com, www.domain2.com) on your local machine. This also means that you can have the same name locally and on your Server as long as you change the host entries in the host file. You can read about setting up virtual host on your Server here, but we will be looking at later in this guide:How to setup Virtual Hosts on your Linux Apache Webserver
Install Eclipse
There is no apt package for the latest Eclipse Indigo 3.7. Actually it dates to versions back to Eclipse Galilao 3.5. The easiest way, is to start by installing Eclipse Galilao and then upgrading the installation. It sounds tedious but it is not that bad. Here are the steps explained in detail.
First open Ubuntu Software manager and find Eclipse under Get Software > Developer tools > IDEs you can also make a search for eclipse. Then install Eclipse Galilao 3.5. It might take some minutes.
Download Eclipse Indigo 3.7
Now we need to download Indigo. Download Eclipse Indigo 3.7 here to your Downloads folder and extract it to a folder called eclipse_indigo.
Find your Eclipse installation
Open the bash and find where Eclipse is installed. You do that by typing:
By default you should get the the following path: /usr/bin/eclipse.
This is the bash script file which points to the actual Eclipse installation. First we will look at where Eclipse is installed, change the path and move the new eclipse_indigo folder to that location.
Change the path to where you are going to place Eclipse Indigo
The top of the file should look like this. I have added comment to what to change:
# work around for e#290395 / LP: #458703
# https://bugs.eclipse.org/bugs/show_bug.cgi?id=290395
# https://bugs.launchpad.net/bugs/458703
export GDK_NATIVE_WINDOWS=true
export MOZILLA_FIVE_HOME="/usr/lib/xulrunner-$(/usr/bin/xulrunner-1.9.2 --gre-version)"
# EDIT THIS TO YOUR INDIGO FOLDER
ECLIPSE=/usr/lib/eclipse/eclipse
inject_update_site(){
if [ ! -e "$1" ] ; then
echo "W: Cannot find $1" 2>&1
return 1
fi
# EDIT REPOSITORIES
cat - >>"$1" < repositories/http\:__download.eclipse.org_releases_galileo/enabled=true
repositories/http\:__download.eclipse.org_releases_galileo/isSystem=false
repositories/http\:__download.eclipse.org_releases_galileo/nickname=Galileo Update Site
repositories/http\:__download.eclipse.org_releases_galileo/uri=http\://download.eclipse.org/releases/galileo/
EOF
}
Edit the bash script so it looks like this:
# work around for e#290395 / LP: #458703
# https://bugs.eclipse.org/bugs/show_bug.cgi?id=290395
# https://bugs.launchpad.net/bugs/458703
export GDK_NATIVE_WINDOWS=true
export MOZILLA_FIVE_HOME="/usr/lib/xulrunner-$(/usr/bin/xulrunner-1.9.2 --gre-version)"
# CHANGED TO ECLIPSE INDIGO FOLDER
ECLIPSE=/usr/lib/eclipse_indigo/eclipse
inject_update_site(){
if [ ! -e "$1" ] ; then
echo "W: Cannot find $1" 2>&1
return 1
fi
# CHANGED REPOSITORIES
cat - >>"$1" < repositories/http\:__download.eclipse.org_releases_indigo/enabled=true
repositories/http\:__download.eclipse.org_releases_indigo/isSystem=false
repositories/http\:__download.eclipse.org_releases_indigo/nickname=Indigo Update Site
repositories/http\:__download.eclipse.org_releases_indigo/uri=http\://download.eclipse.org/releases/indigo/
EOF
}
Move your Eclipse Indigo
Now we move the Eclipse Indigo folder “eclipse_indigo” to the path we have just specified: /usr/lib/eclipse_indigo
You have now successfully installed Eclipse Indigo 3.7 and can test it by launching Eclipse from your Applications > Programming > Eclipse.
Install PHP Development Tools (PDT)
Now we need to install PHP development environment which is called PDT. This is the preferred PHP development plugin for Eclipse. Here are the detailed steps for installing PDT:
- Open Eclipse and go to Help > Install New Software. This opens the plugin manager.
- From the dropdown. Choose Indigo – http://download.eclipse.org/releases/indigo
- Then choose the PHP Development Tools (PDT) SDK Feature. The easiest way is to filter on pdt in the search box. The feature is included in several categories. Just choose one.
- Click Next > Next > accept license > Finish
- Restart Eclipse
You have now installed Eclipse with PDT PHP development environment. Test it by creating a new PHP project.
Setup a new Web Site
Remember I talked about virtual hosts earlier on. Well this is the way to go. We have made another guide where we have included a bash script which does the job for you, but here we are going to do it by hand to understand the steps. We always recommend to use bash scripts. How to setup Virtual Hosts on your Linux Ubuntu 10.04 or 11.04 Apache Webserver
Create a new PHP project in Eclipse
But before we setup virtual host we create a new PHP Project in Eclipse. Give it the name myproject, it is always good to do MS style in Open Source. Create it in your default workspace: /home/user/workspace and click Finish.
Setup Virtual Hosts
First we have to enable the Apache mod vhost_alias. This is done by writing the following command in the bash:
Create Virtual Host
Then we create the alias file. This is the file which tells Apache your web project settings and location. The easiest way is to copy the default virtual host entry file “default” and add your custom settings.
First copy the default entry and name the copy myproject.localhost:
Change virtual hosts file
Now you have a new file called myproject.localhost in your /etc/apache2/sites-available folder. Open the file with your favorite editor and change it so it looks like this. Comments to what to change is added in CAPITAL letters:
ServerAdmin webmaster@localhost
# ADD THE SERVERNAME
ServerName myproject.localhost
# CHANGE THE DOCUMENT ROOT TO YOUR MYPROJECT DIRECTORY
# !!! REMEMBER TO CHANGE USER WITH YOUR USERNAME !!!
DocumentRoot /home/user/workspace/myproject
<Directory />
Options FollowSymLinks
# ALLOW OVERRIDE TO ENABLE VIRTUAL HOSTS
AllowOverride all
</Directory>
<Directory /home/user/workspace/myproject/>
Options Indexes FollowSymLinks MultiViews
# ALLOW OVERRIDE TO ENABLE VIRTUAL HOSTS
AllowOverride all
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
Activate the new site
Save the file and activate the virtual configuration like this:
Create a new host entry
Now we need to tell the computer that we are hosting this site locally. This is done by navigating all incoming traffic to myproject.localhost to your local PC.
First open the file:
And add this line to the end of the file:
Test the new site
Now go back in the project in Eclipse and create a new file called index.php and add the following lines of code:
Test your new web site in your favorite browser on this address: http://myproject.localhost/
Now we are almost done, but are yet missing the greatest feature of them all – Debugging!
Install and Setup Xdebug:
If you are not familiar with debugging. I would strongly advise you to learn it. It enables you to step through code line one by one and examine all the changes. This is great for both understanding code and more important, identify errors. A must have for all developers and Xdebug is the preferred debug plugin for Eclipse and the Apache Web Server.
Install Xdebug
First we install the package on the machine and then we have to configure the settings for Apache. Installation is done by opening your bash and writing the following command:
Edit the configuration file
Edit the configuration file for xdebug. Open the file in nano or your preferred text editor:
It should by default look like this:
Now change it so it looks like this:
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
Restart the Apache Web Server
Now the Xdebug plugin should be ready and running on the Server, let’s test it.
Test the Xdebug installation on the Apache Server
Now we want to be sure that Xdebug is installed on the server. So open the file in your favorite browser in the same path as before: http://myproject.localhost/. The function phpinfo() outputs a large amount of information about the current state of PHP. This includes information about PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License.
Search for xdebug and you should find something like this. Further down you can see the detailed configuration of Xdebug.
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
We are almost there. I know the setup is a bit long, but believe me if you haven’t used debugging before you’ll thank me later.
Setup Eclipse for debugging
Now we just have to set the settings for debugging in Eclipse and we are ready to start coding.
Open Eclipse and change preferences
Choose which browser to use. I use Firefox as external web browser.
Open Eclipse and go to Window > Preferences > General > Web Browser
Choose “Use external web browser” and check the Firefox box below. If Firefox or your browser isn’t listed click on New… and add the path to your desired web browser. For Firefox it’s:
/usr/bin/firefox
Create a new debug configuration
Then you need to setup your debug configuration, there are two paths to do this. One is where you choose Run > Debug Configurations and the other is by clicking on the arrow next to the BUG. Both will open the Configurations settings. Let’s create a debug configuration for our myproject yeah…
- First double click PHP Web Page at left and a new configuration will get created.
- Give it a name “myproject”.
- Choose XDebug as Server Debugger
- Choose a New to PHP Server. A new dialog should open. Give it a name myproject and the following Base URL: http://myproject.localhost. Then press OK
- File: Browse and choose the index.php file
- And finally turn off Auto Generate URL and clear the last input box as it is the index.php file (this is rub by default)
- Click Apply and then close
Start debugging!
First add some code to test debugging. We are going to add a for loop. Go to the index.php file you created earlier and add the following lines of code at the top.
Place breakpoints in the code
Now you place a breakpoint in the index.php file. This indicates where execution should stop.
Where it says echo $i double click left of the line number. This should place little blue dot. This is actually not necessary since the debug configuration by default stops at the first line. But breakpoints are one of the most important features of debugging, so it’s good to know them and see how the work.
Debug
Now let’s start. Click on the arrow to the right of the BUG and choose myproject. Debugging should start and Eclipse will per default ask you if you want to open the debug perspective, answer yes and you can now see an arrow on the left of the first line of PHP code.
If you choose to press F6 you step through the code and if you press F5 you step into the code (f.x. a function). At the top middle you can see how all the values of your variables and see how they change during execution. Play around with it. If there is interest I might make a Youtube video which shows some debugging features. This is absolutely one of the most important tools in modern programming.
Final thoughts
This setup works like a charm on my setup which is running in a VirtualBox. It’s actually faster than the setup I before had on my Windows 7 machine so I would recommend all to give Linux Ubuntu 11.04 a try. When you are using a VirtualBox the setup is easy to setup. The Open Source community have really come far and in my opinion a good direction.
Support this site by adding us to Facebook and get more guides & tips.





Posted in
Tags:
«







Hi,
thanks for this tuto. But I have an issue. I ve done it with ubuntu 10.04. The breakpoints work normally but I do not get the errors and warning message, is that the same for you. I made my test with this index.php file :
I made an other installation on 11.10 with the last “all in one” eclipsePHP and the xdebug from xdebug.org site with the same result, can not get the error message in the debug output view. I do not understand why.
Hope you can help me.
Thanks so much for this! I was trying to get cURL installed on PHP (Ubuntu 11.04), and this article told me exactly what I needed to do in order to make that happen in no time! Thank you, Thank you, Thank you!
Sounds good, thanks for the feedback!
Sry for the late response. Try checking your php.ini file for error output.
To display error messages caused by your PHP script you can include these lines of code:
ini_set(‘display_errors’,1);
error_reporting(E_ALL);
Another way to do it is to edit your php.ini file and include this option:
error_reporting = E_ALL
Hi,
thanks for the tut, but when I go and install xdebug, it seems it was successful, but the last line – with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans – doesn’t appear where it should (in the php info page).
Should it? I should note I already had Eclipse Indigo latest version, didnt have to update (dont know if that changes anything)
Excellent tutorial. Perfectly clear. Got it up and running it no time. Thanks!