Ubuntu, PHP, NetBeans - part I

This article is about installing PHP environment - PHP, Apache, MySQL and xDebug in Ubuntu 8.04. Everything is available through the default Ubuntu repositories, so it should not be hard. I did this last week, when I prepared a machine for our UI study. It's expected that you have already installed Ubuntu or you use VirtuaBox and you have installed Ubuntu as a virtual machine.

Open a terminal. You will need to install all the parts as root, so you have to execute commands trough sudo or  you can in the terminal write command

$ sudo bash

and from this time all what you do in this terminal you do as root. There are the steps for installing the PHP development environment:

  1. Install Appache web server

    apt-get install apache2

  2. Install MySQL server

    apt-get install mysql-server

    The installation of MySQL server will ask for password for root user. It's not mandatory, but I recommend to enter a password.

  3. Install PHP 5

    apt-get install php5

  4. Install MySQL extension for PHP

    apt-get install php5-mysql

  5. Install xDebug extension for PHP - the extension for debugging.

    apt-get install php5-xdebug

  6. This all what you have to install. Now we will set up Apache and PHP.

  7. Setup the Apache web server to use users web sites

    After installing Apache the server should be running. If you click this link http://localhost/ the Firefox is opened and you should see the same content as is on the picture. 


    But when you try the url, which acces web sites in your home folder, it fails. Instead petr write your username:).

    To get it work you have to:
    • Enable userdir module in Apache web server

      a2enmod userdir

    • Create public_html folder in your homedir (do it uder your account, not as root)

      mkdir public_html

    • Restart Apache web server

      /etc/init.d/apache2 restart

      If you do it correctly after refreshing Firefox you should see empty content of the folder as on the picture.

  8. Enable remote debugging in xDebug

    In the folder public_html create index.php file with content:
    Refresh Firefox and you should see how the PHP runtime is setup. Search for the property xdebug.remote_enable property. By default this property is switched off as you can see on the picture.

    To enable this property you have to open file /etc/php5/conf.d/xdebug.ini and add line


    and restart the Apache web server

    /etc/init.d/apache2 restart

This is all. Now you are ready to start develop a PHP application. Next I will write how to instal JRE (Java Runtime Environment) or JDK (Java Development Kit) and NetBeans PHP. Also I will describe how to check, whether the debugging and MySQL database work well.


A cent.... next time use a2enmod instead of the two ugly symlinks... regards

Posted by Marcelo Morales on June 30, 2008 at 04:51 PM CEST #

Thanks Marcelo. I have corrected this in the blog.

Posted by Petr Pisl on July 01, 2008 at 12:36 PM CEST #

A great article - many thanks.
I am 1 day in with Ububtu.
Have installed PHP5, and it works. Can amend the 'xdebug.ini' file but cannot save it. Cannot gain administrator status. All reference materials say admin access can be made through sudo commands, but cannot open editor from there.
Think same problem is preventing the import of ttf files in the fonts directory.
Any help would be appreciated.

Posted by John CLAYTON on July 13, 2008 at 12:47 PM CEST #

Sorry about the post.

Have solved the problem.

Thanks again for article.

Posted by John CLAYTON on July 13, 2008 at 01:05 PM CEST #

sudo tasksel

install lamp and voila php, apache & mysql are installed and configured, except for the xdebug part.

Posted by Doug Holton on July 15, 2008 at 05:13 PM CEST #

your comment system is broken.

I tried to post a response and it says I am using blacklisted words.

Just use sudo tasksel

Posted by Doug Holton on July 15, 2008 at 05:15 PM CEST #

Hi Doug,

thanks for the tip. It's easier. I will try it on fresh ubuntu installation.

And you are right. Your first comment was marked as a spam.


Posted by Petr on July 15, 2008 at 05:26 PM CEST #

thank u r information

it very useful

Posted by Matthew on October 22, 2008 at 07:46 AM CEST #

<p>many thanks</p>

Posted by lava on November 26, 2008 at 08:51 PM CET #

Thankyou for the tutorial. I have a problem, until "its work" is fine, but after making directory its give 404 error, any thoughts??

Posted by farrukh on March 26, 2009 at 02:05 PM CET #

First thanks for the tutorial! But somehow I cannot really get xdebug work with xampp on ubuntu karmic.
Could you make an additional small tutorial for install & config on xampp too? that would be really great!!
I have xampp and also the developers-package installed. But now.... I'm stucked in the middle :-|

THX & Regards

Posted by Ari on December 01, 2009 at 06:08 AM CET #

I have followed your tutorial and setup my lamp + ide. I think this combination is better than wamp or xampp. Than , I have finished my project

http://www.bizimoyunsitesi.com .

Thanks for this post.

Posted by Taner Ozdas on April 07, 2010 at 11:02 AM CEST #

You could have saved yourself a bit of typing with:

sudo tasksel

Posted by Dave C on July 02, 2010 at 12:13 PM CEST #


Posted by trang on January 13, 2011 at 09:44 PM CET #

I already do the first steps but when i put the index.php or even index.html in that folder and try to browse my browsers keeps asking me for download such file never browse anything PLEASE HELP !!!!

Posted by Amado Diaz on March 14, 2011 at 10:26 PM CET #


Thanks for a great tutorial, I managed to do everything right, both ways(installed everything manually and also with tasksel) but still, when I put index.php in the public_html dir it just wants to download it. Can anyone help me with this? Am I doing something wrong? Ubuntu 10.04 Lucid Lynx LTS used.



Posted by Danny on November 04, 2011 at 11:42 AM CET #


I had the same problem about not executing the php file. The answer is that for some reason the default php configuration had the execution of php from user directories disabled. Just edit the conf file, comment the lines that it says and restart the apache server

sudo gedit /etc/apache2/mods-enabled/php5.conf

Posted by Dimitris on January 24, 2012 at 11:40 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed

This blogs is written by NetBeans developers who contribute to the PHP support mainly.


« April 2014