A.6 What's Needed for This Book
This section shows you how to download and install our example
database, all of the book code examples, the sample online winestore
application, and the additional packages that are used throughout the
book.
A.6.1 Installing PEAR Packages
The
following optional PEAR package is required:
- HTML_Template_IT
-
This is needed to work with Chapter 7 and all
later chapters.
Detailed instructions to install optional packages can be found in
Chapter 7. You'll also find a
discussion there about how to find about, install, and upgrade
packages.
In brief, to install and upgrade the packages you need for this book
do the following:
Log in as the root user. If you're not already, connect to the Internet. Type the following to install the optional package: % pear install HTML_Template_IT
Type the following to check if upgrades of the core packages used in
this book are available: % pear upgrade PEAR
% pear upgrade Date
% pear upgrade DB
% pear upgrade Mail
A.6.2 Installing the Code Examples
The example PHP scripts in this book
are available from our book's web site, http://www.webdatabasebook.com. In this
section, we show you how to install them for use on your machine. The
winestore application isn't installed in this
section; see Section A.6.5 for
instructions.
We assume you've already followed the instructions
in this chapter to install MySQL, PHP, and Apache. We also assume
you've installed these tools in the locations we
recommend; if you haven't, replace the directory
/usr/local/apache2/htdocs with your document
root location during the following steps.
To install the example scripts, follow these steps:
Using a browser, download the file http://www.webdatabasebook.com/examples.zip
into the /tmp directory. To start, you need to configure your Apache web server so that it
won't show users the content of the
.inc include files if they're
retrieved with a web browser. There are several ways to do this, but
the simplest is to edit your httpd.conf
configuration file. You'll find the file in
/usr/local/apache2/conf/. To edit the file,
you'll need to login as the root user. Now, open the httpd.conf file in an editor, and
add this to the end of the file: <Files ~ "\.inc$">
Order allow,deny
Deny from all
Satisfy All
</Files>
Save the file and exit the editor. You now need to restart your
Apache server. You can do this by typing: % /usr/local/apache2/bin/apachectl restart
Now, create a directory in your Apache document root to store the
examples, and copy the downloaded file to that location: % mkdir /usr/local/apache2/htdocs/wda
% cp /tmp/examples.zip /usr/local/apache2/htdocs/wda
Unzip the wda.zip examples in their new
directory by doing this: % cd /usr/local/apache2/htdocs/wda
% unzip examples.zip
Edit the file db.inc in the
wda directory and modify the lines beginning
with $username and $password so
that fred and
shhh are replaced with the username and
password you chose for your user when installing MySQL: <?php
$hostName = "127.0.0.1";
$databaseName = "winestore";
$username = "fred";
$password = "shhh";
Save the file and exit the editor. You may also need to set the file permissions so that examples are
accessible through your web browser. To do this, use: % chmod a+rx /usr/local/apache/htdocs/wda
% chmod a+r /usr/local/apache/htdocs/wda/*
You should now be able to load the example list by requesting the
following URL with a web browser running on the same machine as the
web server: http://127.0.0.1/wda/. Test the
examples from Chapter 2 through Chapter 4—they should work. You'll find that some of the examples from Chapter 6 onward run only if the
winestore database has been loaded into the
MySQL DBMS by following the instructions in the next section. In
addition, most examples from Chapter 7 onward
work only if you've installed the PEAR package
HTML_Template_IT.
A.6.3 Installing the PDF PHP Library
To work with the PDF PHP library in
Chapter 13, you need to download the class
files. To do this, follow these steps:
Visit the web site http://ros.co.nz/pdf/. From the Downloads section, choose the link to the Zip file that
contains the class, sample, and the required font metric files. Save
the file in /tmp. Change directory to the temporary directory and unzip the download
file. into an install directory. If you're only planning to use the library with our
examples, first install the code examples as described in the
previous section, and then use: % unzip pdfClassesAndFonts_009e.zip -d /usr/local/apache2/htdocs/wda
This installs the class files and fonts in the examples directory. An alternative approach is to install the files into a shared file
location such as /usr/local/src/pdf-php. Then,
edit your php.ini file and include the directory
at the end of the include_path directive. This
allows you to include the path in a PHP script using only the class
name and without specifying the directory.
A.6.4 Loading the Winestore Database
A local copy of the
winestore
database is required to test the
SQL examples in Chapter 5, to test some of the
web database application examples in Chapter 6 through Chapter 13, and to
use the sample winestore application described in Chapter 16 through Chapter 20. In
addition, MySQL must be installed and configured before the
winestore database can be loaded.
We assume you've installed MySQL in the location we
recommend; if you haven't, replace the directory
/usr/local/mysql with your MySQL installation
directory in the following steps.
The steps to load the winestore database are as
follows:
Using a web browser, download the file http://www.webdatabasebook.com/database.zip
into the /tmp directory. Uncompress the winestore database in any directory by typing the
following in a shell window: % unzip database.zip
Run the MySQL command-line interpreter using the root username and
the password you set, and load the
winestore database: % /usr/local/mysql/bin/mysql -uroot -p
password
< /tmp/winestore.data
Be patient, this may take a while. Exit the command interpreter by
typing quit. After the loading is complete (it may take a while) the database can
be tested by running a query. To do this, use the
username and
password you created when installing and
configuring MySQL: % /usr/local/mysql/bin/mysql -uusername -ppassword
Now type: mysql> SELECT * FROM region;
This should produce the following list of wine regions as output: +-----------+---------------------+
| region_id | region_name |
+-----------+---------------------+
| 1 | All |
| 2 | Goulburn Valley |
| 3 | Rutherglen |
| 4 | Coonawarra |
| 5 | Upper Hunter Valley |
| 6 | Lower Hunter Valley |
| 7 | Barossa Valley |
| 8 | Riverland |
| 9 | Margaret River |
| 10 | Swan Valley |
+-----------+---------------------+
The winestore database has now been loaded and
tested.
A.6.5 Installing the Winestore Application
The sample online
winestore application is
available from our book's web site, http://www.webdatabasebook.com. In this
section, we show you how to install it on your machine.
We assume you've installed the
winestore database by following the instructions
in the previous section. We also assume you've
already followed the instructions in this chapter to install MySQL,
PHP, and Apache, and that you've installed these
tools in the locations we recommend; if you haven't,
replace the directory /usr/local/apache2/htdocs
with your document root location in the following steps.
Follow these steps:
Using a browser, download the file http://www.webdatabasebook.com/wda2-winestore.zip
into the /tmp directory. If you haven't configured your Apache web server so
that it won't show users the content of the
.inc include files, follow Step 2 in
Section A.6.2. Log in as the root user and move the application into your Apache
document root: % cp /tmp/wda2-winestore.zip /usr/local/apache2/htdocs/
Unzip the wda2-winestore.zip code in the
document root directory. This will create the subdirectory
wda2-winestore: % cd /usr/local/apache2/htdocs/
% unzip wda2-winestore.zip
Edit the file wda2-winestore/includes/db.inc and
modify the lines beginning with $username and
$password so that fred
and shhh are replaced with the username
and password you selected when configuring MySQL: <?php
$hostname = "127.0.0.1";
$databasename = "winestore";
$username = "fred";
$password = "shhh";
Save the file and exit the editor. You may also need to set the file permissions so that examples are
accessible through your web browser. To do this, use: % chmod a+rx /usr/local/apache2/htdocs/wda2-winestore
% chmod a+r /usr/local/apache2/htdocs/wda2-winestore/*
You should now be able to load the application index by requesting
the following URL with a web browser running on the same machine as
the web server: http://127.0.0.1/wda2-winestore/. Click on
the Use the Application link and you should be able to use the
application.
|