Practical Database Programming With Java
.pdf
5.3 Exploring NetBeans IDE 6.8 279
Figure 5.118. Default settings for the HTTP Server.
5.3.7.3 Configuring and Testing the Installed Apache HTTP Web Server
Now let’s configure and test our installed Apache HTTP Server. The main configuring jobs are executed inside the configure file named httpd.conf that is located at the folder
C:\Program Files\Apache Software Foundation\Apache 2.2\conf. This configuration is not necessary if your installed HTTP Server can work on your computer without any problem. To test this server, first let’s start it by going to Start\All Programs\Apache HTTP Server 2.2\Control Apache Server\Start menu item. If the server can start without any problem, or you cannot find any debug or error information from the pop-up command window, which means that your server does not need to be configured and you can use it without problem.
However, if you did get some error information from the popup command window, you need to correct them by modifying your httpd.conf file.The most common problem is the port number you are using, and it may be used by some other devices. The reason for that is because in most situations, the default Web server, Internet Information Services (IIS), will be installed in your computer when you installed your Windows operating system, and this server will use port 80 as the default port. Therefore, our installed Apache HTTP Server cannot use the same port.
To solve this problem, we need to configure the Apache HTTP server by modifying the server configuring file, httpd.conf, which is located at the folder C:\Program Files\Apache Software Foundation\Apache2.2\conf. Go to that folder and double click on the configuring file httpd.conf to open it. In normal case, we can open it in the NotePad format.
On the opened file, browse down the file and try to find the command line like
Listen 80
Change the port number from 80 to any other available port number, such as 800. Then save this configuring file. Open a Web browser and enter http://localhost:800 to the
280 Chapter 5 Introduction to NetBeans IDE
Figure 5.119. The successful server page.
Address field. Press the Enter key and you will find that the successful Apache HTTP Server welcome page is displayed, as shown in Figure 5.119.
5.3.7.4 Downloading and Installing the PHP Engine
Download the current PHP engine by going to the site: http://www.php.net/downloads.php. The current PHP engine version is PHP 5.3.2. Click on the link http://windows.php.net/ download/ to begin this downloading process, since we need to download a Windows Binaries package that can be installed later on when the downloading is complete.
On the next page, you can select a Non Thread Safe or Thread Safe version to download. In our case, we prefer to select Thread Safe version. Click on the Installer from the VC9 x86 Thread Safe group to begin this downloading process. It is recommended to first save this package to your Temp folder, and then you can click the downloaded file to being the installation process.
When the saving process is complete, click on the Open Folder button to open the Temp folder, then double click on the downloaded file php-5.3.2-Win32-VC9-x86. msi and click on the Run button to begin the installation process.
A PHP 5.3.2 Setup dialog is displayed, as shown in Figure 5.120. Click on the Next button to continue.
Check the Accept Items checkbox and the Next button to go to the next wizard. Keep the default location, C:\Program Files\PHP\ unchanged and click on the Next button to continue.
In the next wizard, check the Apache 2.2x Module radio button from the server group to make this as our default Web server. Click on the Next button to continue.
In the next opened wizard, click on the Browse button to browse to our default HTTP Server configuration folder, C:\Program Files\Apache Software Foundation\Apache 2.2\conf, and we need to use this folder to store the configuration file for the PHP engine. Your finished wizard should match one that is shown in Figure 5.121.
Click on the Next button to go to the next wizard.
In the next wizard, select all icons from the available sources since we want to install all of components, as shown in Figure 5.122.
Click on the Next and Install button to begin this installation process. Then click on the Finish button to close this wizard when the installation is complete.
5.3 Exploring NetBeans IDE 6.8 281
Figure 5.120. The PHP 5.2.3 Setup dialog box.
Figure 5.121. The selected Apache configuration directory.
Before we can continue to use this installed PHP engine, we need to test it to confirm that this installation is fine and the installed engine will work.
5.3.7.5 Testing the Installed PHP Engine
To check that the PHP engine has been installed successfully and PHP processing has been enabled in the Apache configuration, we need to test this engine by performing the following operations:
282 Chapter 5 Introduction to NetBeans IDE
Figure 5.122. Select all components.
<?php
echo "PHP has been installed successfully!";
?>
Figure 5.123. The coding for the testing file.
1.Start the Apache HTTP Server by going to Start\All Programs\Apache HTTP Server 2.2\Control Apache Server\Start menu item and click on the Start item.
2.Open a new NotePad file and enter the codes that are shown in Figure 5.123 into this file.
3.Save this file as the name of test.php to the folder: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs.
Note: To save this file to a php format in the NotePad, you need to use the double quotation marks to cover the file name. In this case, it should be “test.php.”
4.Open the Internet Explorer and enter the URL: http://localhost:800/test.php into the Address field. A successful PHP engine running result should be displayed, as shown in Figure 5.124.
5.3 Exploring NetBeans IDE 6.8 283
Figure 5.124. The successful testing result for the installed PHP engine.
#AddEncoding x-compress .Z #AddEncoding x-gzip .gz .tgz
#
#If the AddEncoding directives above are commented-out, then you
#probably should define those extensions to indicate media types:
AddType application/x-compress .Z AddType application/x-gzip .gz .tgz
AddType Application/x-httpd-php .php
#
#AddHandler allows you to map certain file extensions to "handlers":
#actions unrelated to filetype. These can be either built into the server
#or added with the Action directive (see below)
Figure 5.125. The modified httpd.conf file.
Note: If you cannot open this page, which means that your PHP engine cannot start or work properly. The solution is to modify the httpd.conf file to add one more command:
AddType Application/x-httpd-php .php under two AddType commands that are located about line 380. To track this file with the line number, click on the View menu item in the NotePad and check the Status Bar.
An example of adding this command is shown in Figure 5.125. The added command has been highlighted in bold.
At this point, we have successfully installed and configured Apache HTTP Server and PHP engine in our computer. Next, let’s start to develop and build our PHP project to perform data actions between our project and our desired databases.
5.3.7.6 Creating a PHP Project
In this section, we will create and set up a PHP project in NetBeans IDE 6.8. Perform the following operations to complete this creation and setup:
284 |
Chapter 5 Introduction to NetBeans IDE |
|
1. |
Start the NetBeans IDE 6.8 and switch to the Projects window. |
|
2. |
Choose File > New Project. The Choose |
Project panel opens. |
3. |
Select PHP from the Categories list, and PHP |
Application from the Projects |
|
list since we want to create a new PHP project without using any existing source. Click on |
|
|
the Next button to continue. |
|
4. |
In the opened New PHP Project wizard, enter PHPCustomer into the Project |
|
|
Name field, keep all default settings unchanged, and click on the Next button to |
|
|
continue. |
|
5. |
In the Run Configuration wizard, we can select the following three different running |
|
|
configurations for this project: |
|
A.Local Web site
B.Remote Web site (FTP)
C.Script
The Local Web site configuration is to run this project in our local Web site using the Apache HTTP server. By using this configuration, it involves a copy of your PHP source folders in the Web folder of the Apache web server installed on your machine.
The Remote Web site configuration is to run your project in a remote Web site with a hosting account on a remote server and an FTP account on that server. You need to deploy and upload your complete project to the Web server on which your project will run.
The Script configuration does not require that a Web server be installed and running on your computer. You only need a PHP engine to run your project.
6. To make it simple, in this application, we just want to run our project in our local Web site. Therefore, select the Local Web site from the Run As combo box and enter http://localhost:800/PHPCustomer/ into the Project URL combo box. Keep the Copy files from Sources Folder to another location checkbox unchecked since we do not want to save our project files to other location.Your finished Run Configuration wizard should match one that is shown in Figure 5.126. Click on the Next button to continue.
7. Click on the Finish button on the next wizard to complete this creation process.
Figure 5.126. The finished Run Configuration wizard.
5.3 Exploring NetBeans IDE 6.8 285
Figure 5.127. The default starting page of the new PHP project.
As a new PHP project is created, the starting page, index.php, is displayed with the default php codes, as shown in Figure 5.127.
Next, let’s handle our target database server issue since we need to connect to our database via server to perform data actions between our PHP project and that database.
5.3.7.7 Downloading and Configuring MySQL Database Server
As we know, the most popular database used in PHP is MySQL database. Currently, the only Web server database supported by PHP is MySQL.Therefore, we need to first download a MySQL database server and use it in this PHP application.
Go to the site http://www.mysql.com/downloads/mysql/ to begin this downloading process.
On the opened page, select the first item, Windows (x86, 32-bit), MSI Installer Essentials, and click on the Download button to go to the next page.
In the next page, click on the No Thanks, just take me to the downloads link to continue. Select a source mirror that is close to you and click on the related HTTP link to save this program to the Temp folder in your computer. When this download is complete, open the Temp folder and double click on the downloaded file to install it.
Click on the Next button to continue.
Select the Typical radio button and click on the Next button to continue. Click on the Install button to begin this installation process. The installation starts, as shown in Figure 5.128.
Click on the Next buttons and the Finish button to complete this process.
The MySQL Server Instance Configuration Wizard is appeared. Click on the Next button to go to the next wizard. Select the Detailed Configuration item in the next wizard, as shown in Figure 5.129, and the Next button to continue.
Select the Developer Machine item in the next wizard since we need to develop our PHP applications and run them in our local machine. Click on the Next button to continue.
286 Chapter 5 Introduction to NetBeans IDE
Figure 5.128. The installation process of the MySQL database.
Figure 5.129. The server configuration selection process.
In the next wizard, keep the default selection, Multifunctional Database, unchanged, and click on the Next button to continue.
In the next wizard, select \MySQL Datafiles\ as the directory to save the InnoDB tablespace. Click on the Next button to continue.
Keep the default settings for the next two wizards, including the default port of 3306, and click on the Next button to continue.
In the next wizard, select the Best Support For Multilingualism item to make all default character sets as UTF8, as shown in Figure 5.130. Click on the Next button to continue.
In the next wizard, keep all default settings unchanged and check the Include Bin Directory in Windows PATH checkbox, as shown in Figure 5.131, since we may need
5.3 Exploring NetBeans IDE 6.8 287
Figure 5.130. The character set selection.
Figure 5.131. Install the MySQL as a window server.
to start this server from the command window later. Click on the Next button to continue.
In the next wizard, you need to provide a new root password. You can use any valid password if you like. In this application, we used reback as our new root password. You need to remember this password since you need to use it later to start this server.
Enter this root password reback to both root password and Confirm fields, and check the Enable root access from remote machines checkbox. Your finished root password selection wizard should match one that is shown in Figure 5.132.
Click on the Next button to continue.
288 Chapter 5 Introduction to NetBeans IDE
Figure 5.132. The finished root password selection wizard.
Figure 5.133. The successful configuration dialog box.
In the opened next wizard, click on the Execute button to start this configuration process. If everything is fine, a successful configuration dialog box is displayed, as shown in Figure 5.133.
Click on the Finish button to complete this installation and configuration process.
5.3.7.8 Configuring the MySQL Server in NetBeans IDE
To configure our installed MySQL database server in NetBeans IDE 6.8 and create a new user for MySQL database to be created later, perform the following operations:
