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.
To follow this tutorial, you need the following software and resources.
|Software or Resource||Version Required|
|NetBeans IDE||PHP download bundle|
|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.
This tutorial shows how to configure the PHP development environment in Ubuntu 7.04 and later. You need to:
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.
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:
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:
apt-get --purge remove php5-common
apt-get install php5 phpmyadmin
/etc/apache2/sites-available/defaultwith the document root
/var/www/We recommend that you create your own virtual host and enable it instead of editing the default one.
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite
gksudo gedit /etc/apache2/sites-available/mysiteIf asked, enter the password that you specified for the root user during the installation of your operating system.
sudo a2dissite default && sudo a2ensite mysite
sudo /etc/init.d/apache2 reload
mysql -u root -pThe MySQL command prompt appears.
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)
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.
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.
To build XDebug from sources you need two additional modules: PHP5 Development and PEAR.
Note: You can also install the modules by running the following command in the Terminal window: aptitude install php5-dev php-pear
sudo pecl install xdebug
gksudo geditIf asked, enter the password specified for the root user during the installation of your operating system.
Check here for more details on configuring XDebug.
To send comments and suggestions, get support, and keep informed on the latest developments on the NetBeans IDE PHP development features, join the firstname.lastname@example.org mailing list.Back to the PHP Learning Trail