Configuring PHP Development Environment in Linux Ubuntu Distribution
Contributed by Barbara Mityashina
June 27, 2008
Contents
Required Software
To create, run, and debug your PHP projects you need the following software:
- The NetBeans IDE for PHP. Downloads are available here.
- A web server. Typically development and debugging is performed on a local web server, while the production environment is located on a remote web server. The current version enables using a local server. Using a remote server with FTP access will be supported in future versions. PHP support can be added to a number of web servers (IIS, Xitami, and so on), but most commonly Apache HTTP Server is used. Click here for information on how to install and configure Apache 2.2.
- The PHP engine. The supported version is PHP5. Downloads are available here.
- The PHP debugger. The NetBeans IDE for PHP allows you to use XDebug, but using a debugger is optional. The recommended version is XDebug 2.0 as it is compatible with PHP5.
- A database server. You can use various database servers while one of the most popular ones is the MySQL server. Downloads are available here.
Note: The recommended version of the product is MySQL Server 5.0. The provided documents describe the work with this version.
After the installation, you need to set up the environment that all the software components work properly with each other.
The current document describes the configuration of PHP development environment in the Ubuntu-6.06 operating system. You need to:
- 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.
- Specify the Document Root for the Apache2 HTTP server
- Configure the MySQL database server
- Install and enable the XDebug 2.0 debugger
See
here for information on installing Apache, MySQL, and PHP separately.
Installing the Software
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
- Choose Applications > Add/Remove. The Add/Remove Applications panel opens.
- The left hand panel shows a list of applications available for installing. Press Advanced.
- The Enter your password to perform administrative tasks dialog box opens.
- 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.
- The Quick Introduction information panel opens. Read the information and click Close.
- The Synaptic Package Manager panel opens with a list of available packages.

Selecting the Packages to Install
- 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.
- 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.
- The system returns to the Synaptic Package Manager panel where the selected packages are marked
for installation.
- Choose Apply on the toolbar. The Apply the following changes summary panel opens with a list of
packages selected for installation. Click Apply.
- When the download and installation are completed successfully, the Changes applied panel opens.
Click Close.
Checking the Installation
- 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:

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
- Choose Places > Home Folder.
- From the context menu, choose Create Folder.
- Enter the name of the folder, for example, public_html.
Creating a New Virtual Host
- To launch the Terminal, choose Applications>Accessories>Terminal.
The Terminal window opens.
- 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
- 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.
- Change the Document Root to point to the new location:
/home/<user>/public_html/
- Change the Directory directive, replace
<Directory /var/www/>
with
<Directory /home/user/public_html/>
- Save the file mysite
Activating the New Virtual Host
- 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
- 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.
- 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.
- 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.
- Start the Synaptic Package Manager.
- Switch to the Installed panel to check that the make module is already installed.
- Switch to the All tab and click the check boxes next to the following packages:
For each item, from the context menu choose Mark for installation.
- 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.
- The system returns to the Synaptic Package Manager panel where the selected packages are marked
for installation.
- Choose Apply on the toolbar. The Apply the following changes summary panel opens with a list of
packages selected for installation. Click Apply.
- 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.
- 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.
- Open the file /etc/php5/apache2/php.ini
.
- 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.
Back to the PHP Learning Trail