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.
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:
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.
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.
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:
php5-dev
php-pear
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.
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.