corner imagecorner image
FeaturesPluginsDocs & SupportCommunityPartners

Configuring PHP Development Environment in Linux Ubuntu Distribution

This tutorial shows how to configure the PHP development environment in the Ubuntu-6.06 operating system. This involves installing and configuring the PHP engine, a MySQL database, an Apache web server, and the XDebug debugger.

Contents

Content on this page applies to NetBeans IDE 6.5

To follow this tutorial, you need the following software and resources.

Software or Resource Version Required
NetBeans IDE PHP download bundle 6.5
A PHP engine Version 5.
A web server Apache HTTP Server 2.2 is recommended.
A database server MySQL Server 5.0 is recommended.
A PHP debugger (optional) XDebug 2.0 or later

Typically, development and debugging is performed on a local web server, while the production environment is located on a remote web server. Setting up a remote web server is described in Deploying a PHP Application on a Remote Web Server Using the NetBeans IDE. This tutorial has you set up a local web server. PHP support can be added to a number of local web servers (IIS, Xitami, and so on), but most commonly Apache HTTP Server is used.

Installing the Software

This tutorial shows how to configure the PHP development environment in the Ubuntu-6.06 operating system. You need to:

  1. Install the Apache2 HTTP server, the PHP5 engine, the MySQL 5.0 database server, and the PHP5-MySQL module that automatically enables support of MySQL with the PHP5 engine.
  2. Specify the Document Root for the Apache2 HTTP server
  3. Configure the MySQL database server
  4. Install and enable the XDebug 2.0 debugger
See here for information on installing Apache, MySQL, and PHP separately.

You can install the software by executing the following command at the command prompt in the Terminal window:

aptitude install apache2 php5 php5-gd mysql-server php5-mysql
To install the software using the interface features, complete the following steps:

Starting the Synaptic Package Manager

  1. Choose Applications > Add/Remove. The Add/Remove Applications panel opens.
  2. The left hand panel shows a list of applications available for installing. Press Advanced.
  3. The Enter your password to perform administrative tasks dialog box opens.
  4. In the Password edit box, enter the password that you specified for the root user during the installation of your operating system and press OK.
  5. The Quick Introduction information panel opens. Read the information and click Close.
  6. The Synaptic Package Manager panel opens with a list of available packages.
    Synaptic Package Manager

Selecting the Packages to Install

  1. On the Synaptic Package Manager panel, tab All, click the check boxes next to the following packages:
    • apache2
    • php5
    • mysql
    • php5-mysql
    For each item, from the context menu choose Mark for installation.
  2. The Mark additional required changes dialog box opens with a list of dependent packages that should be also installed to enable the work of the software. Click Mark.
  3. The system returns to the Synaptic Package Manager panel where the selected packages are marked for installation.
  4. Choose Apply on the toolbar. The Apply the following changes summary panel opens with a list of packages selected for installation. Click Apply.
  5. When the download and installation are completed successfully, the Changes applied panel opens. Click Close.

Checking the Installation

  1. To check that Apache and PHP are installed and running, launch your browser and enter the following URL:
     http://localhost/
    The following page opens where PHP5 engine is included in the notation:
    Apache in Ubuntu running

Specifying the Document Root for the Apache2 HTTP Server

The Document Root is the directory where the Apache HTTP server takes files for displaying in the browser. The Document Root is specified in the file that defines your virtual host. The default virtual host configuration file is
/etc/apache2/sites-available/default
with the document root
/var/www/
We recommend that you create your own virtual host and enable it instead of editing the default one.

Creating the Document Root Location

  1. Choose Places > Home Folder.
  2. From the context menu, choose Create Folder.
  3. Enter the name of the folder, for example, public_html.

Creating a New Virtual Host

  1. To launch the Terminal, choose Applications>Accessories>Terminal. The Terminal window opens.
  2. To copy the configuration file of the default virtual host to a new file (mysite), type the following command at the command prompt:
    sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite
  3. Run the gedit application and edit the new configuration file (mysite) in it:
    gksudo gedit /etc/apache2/sites-available/mysite 
    If asked, enter the password that you specified for the root user during the installation of your operating system.
  4. Change the Document Root to point to the new location:
    /home/<user>/public_html/
  5. Change the Directory directive, replace
    <Directory /var/www/>
    with
    <Directory /home/user/public_html/>
    Change Directory Root in Ubuntu
  6. Save the file mysite

Activating the New Virtual Host

  1. To deactivate the default host and activate the new host, launch the Terminal and run the following two utilities in the Terminal window:
    sudo a2dissite default && sudo a2ensite mysite
  2. Restart the Apache HTTP server:
    sudo /etc/init.d/apache2 restart>

Configuring the MySQL Database Server

During the installation of the MySQL database server, a root user is created. By default, no password is specified for the root MySQL server user. You need to connect to the MySQL server and specify a password for the root user. You will need the password for creating other MySQL server users.
  1. To connect to the MySQL server, launch the Terminal and in the Terminal window enter the following command:
    mysql -u root
    The MySQL command prompt appears.
  2. At the command prompt enter the following command and press Enter:
    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('<yourpassword>');
    If the command is executed successfully, the following message is displayed:
    Query OK, 0 rows affected (0.00 sec)

Installing and Enabling the XDebug Debugger

All the below steps are required only if you want to use XDebug, which is optional for PHP development.

Installing the PHP5 Development and PEAR Modules

To build XDebug from sources you need two additional modules: PHP5 Development and PEAR.

  1. Start the Synaptic Package Manager.
  2. Switch to the Installed panel to check that the make module is already installed.
  3. Switch to the All tab and click the check boxes next to the following packages:
    • php5-dev
    • php-pear
    For each item, from the context menu choose Mark for installation.
  4. The Mark additional required changes dialog box opens with a list of dependent packages that should be also installed to enable the work of the software. Click Mark.
  5. The system returns to the Synaptic Package Manager panel where the selected packages are marked for installation.
  6. Choose Apply on the toolbar. The Apply the following changes summary panel opens with a list of packages selected for installation. Click Apply.
  7. When the download and installation are completed successfully, the Changes applied panel opens. Click Close.
Note: You can also install the modules by running the following command in the Terminal window:
aptitude install php5-dev php-pear

Installing XDebug

To download and install the XDebug, enter the following command in the Terminal window:
sudo pecl install xdebug

Enabling XDebug

To enable XDebug, you need to edit the php.ini file in the gedit text processor.
  1. To start the gedit text processor, launch the Terminal and type the following command at the command prompt:
    gksudo gedit
    If asked, enter the password specified for the root user during the installation of your operating system.
  2. Open the file /etc/php5/apache2/php.ini .
  3. Add the following lines to the file:
    zend_extension=/usr/lib/php5/20051025/xdebug.so
    xdebug.remote_enable=on

Check here for more details on configuring XDebug.

Using an AMP Package

To download and install the PHP engine, the Apache HTTP Server, and the MySQL database server as one stack, use the XAMPP for Linux package.

Find more information about installing and configuring XAMPP Mac OS X here.



To send comments and suggestions, get support, and keep informed on the latest developments on the NetBeans IDE PHP development features, join the mailing list.

Back to the PHP Learning Trail
Companion
Projects:
MySQL Database Server   GlassFish Community: an Open Source Application Server   Open Solaris  Open JDK: an Open SourceJDK   Mobile & Embedded Community     Sponsored by 
Sponsored by Sun Microsystems