Monday 25 May 2015

Configuring the PHP Development Environment With NETBEANS IDE in Linux Ubuntu

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:
  • apache2
  • php5
  • mysql-server
  • php5-mysql

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:
    apt-get --purge remove php5-common
    
    apt-get install php5 phpmyadmin
     

    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.
  • Create the Document Root Location
  • Specify the new document root in a new virtual host
  • Activating the new virtual host

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/>
     

    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 reload
       
       
      Troubleshooting Apache
      If you get this error:
      apache2: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName then use a text editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop to create a new file,
      sudo nano /etc/apache2/conf.d/fqdn or
      gksu "gedit /etc/apache2/conf.d/fqdn" then add
      ServerName localhost to the file and save. This can all be done in a single command with the following:
      echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn


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.
  1. 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.
  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)