Configuring the PHP Development Environment in Linux Ubuntu
This tutorial shows how to configure the PHP development environment in the Ubuntu operating system (7.10 and later). This involves installing and configuring the PHP engine, a MySQL database, an Apache web server, and the XDebug debugger.
See the Ubuntu community for more information on installing Apache, MySQL, and PHP.
Installing the Software Packages Together
Ubuntu provides a Linux AMP (LAMP) package that contains all the necessary packages for your PHP environment. You can install the software by executing the following command at the command prompt in the Terminal window:
sudo tasksel install lamp-server
The lamp-server package includes the most suitable version of PHP, Apache 2, MySQL, and PHP5-MySQL.
Installing the Software Packages Separately
Instead of installing the entire set of LAMP packages, you can also install the packages individually. This is useful if you already have installed one of the components, such as the Apache server or MySQL database server. You can use command-line tools or the Synaptic Package Manager GUI.
The individual packages to install are the following:
Checking the Installation
After you set up your PHP web stack, check that it is installed correctly and that your Apache server recognizes your PHP engine.
To check that Apache and PHP are installed and running, open NetBeans IDE and create a PHP project. In the index.php file, enter the PHP method phpinfo(). Run the file. The standard PHP information page should display.
The following are some frequently encountered problems when checking the installation of your PHP stack in Ubuntu:
The browser window displays a Not Found error for ~USER/PROJECT/index.php. Remove the ~USER string from the URL. For example, if this error appears for the URL ~ubuntu/test1/index.php, change the URL to test1/index.php. Note that you can set the URL for a PHP project in NetBeans IDE either when you create the project, or by right-clicking the project node and going to Properties > Run Configuration.
The browser shows you a popup asking you to open the file, as if the PHP engine is not recognized. There's a problem with your php5-common package. Replace it with php5 and phpmyadmin. To replace php5-common, run the following two commands:
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
with the document root
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:
Change the Directory directive, replace
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 reload
Configuring the MySQL Database Server
During the installation of the MySQL database server, a root user is created.
A dialog opens during installation in which you set a root user password. If
this dialog did not open, or you did not set a password in this dialog, you need
to create a MySQL root user password now.
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 -p
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
The following steps are required only if you want to use XDebug, which is optional for PHP development. XDebug is an extension to PHP. NetBeans IDE uses it automatically when it is configured correctly for your PHP web stack. For more information on XDebug and NetBeans IDE, see Debugging PHP Source Code in the NetBeans IDE. Also see the NetBeans wiki page on XDebug.
Installing the XDebug Package (Ubuntu 8.05 and later)
Starting in Ubuntu 8.05, an XDebug package is available, named php5-xdebug. The supported version of XDebug is 2.0.3-1. You can install it with command-line tools or through the Synaptic Package Manager UI. After you install XDebug, you have to modify php.ini as described in Enabling XDebug.
Building XDebug from Sources (Ubuntu 7.10)
To build XDebug from sources you need two additional modules: PHP5 Development and PEAR.