C.4 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.
C.4.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 out about, install, and upgrade
packages.
Panther has a problem: the PEAR installer doesn't
work and you need to carry out an extra step to get it going. We show
you how to install, upgrade, and fix the problem in the following
steps:
Start by opening Terminal, which is located in Applications
Utilities. Maximize the
Terminal window. In the Terminal window, log in as the root user by
typing: % su
Supply the password you set when unlocking the root user. Let's fix the PEAR installer's
configuration. To do this, you need to set the environment variable
PHP_PEAR_INSTALL_DIR to point to the PEAR
directory /usr/local/php/lib/php. However, when
you use Terminal to type commands, you're using a
shell program, and how you set environment variables is dependent on
the shell you use. Most users use the bash shell. To set an environment variable in
bash, type into your Terminal window: % set PHP_PEAR_INSTALL_DIR /usr/local/php/lib/php
If you know you're using the csh or tcsh shell, then
type: % setenv PHP_PEAR_INSTALL_DIR /usr/local/php/lib/php
If you know how to add environment settings to your shell resource
file (such as .bashrc or
.cshrc), then add the command you just typed to
the end of that file. If you don't do this, then
each time you want to use the PEAR installer, you need to repeat this
step first. 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
C.4.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 C.4.5 for
instructions.
To install the example scripts, follow these steps:
Using a browser, download the file http://www.webdatabasebook.com/examples.zip
into the /tmp directory. Open Terminal, which is located in Applications
Utilities. Maximize the
Terminal window. In the Terminal window, login as the root user by
typing: % su
Supply the password you set when unlocking the root user. 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
/etc/httpd/. To edit the file, login as the root user and edit the file by typing
the following into a Terminal window: % su
% pico /etc/http/httpd.conf
Scroll to the end of the file using the down arrow key. To the end of
the file, add: <Files ~ "\.inc$">
Order allow,deny
Deny from all
Satisfy All
</Files>
Save the file by pressing ctrl-o and then
Enter. Quit pico using ctrl-x.You now need to
restart your Apache server. You can do this by typing: % apachectl stop
% apachectl start
Create a directory in your Apache document root to store the
examples, and copy the downloaded file to that location: % mkdir /Library/WebServer/Documents/wda
% cp /tmp/examples.zip /Library/WebServer/Documents/wda
Unzip the wda.zip examples in their new
directory by doing this: % cd /Library/WebServer/Documents/wda
% unzip examples.zip
Edit the file db.inc in the
wda directory. Type: % pico db.inc
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 by pressing ctrl-o and Enter.
Quit pico using ctrl-x. 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 /Library/WebServer/Documents/wda
% chmod a+r /Library/WebServer/Documents/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 to
Chapter 4, and 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.
C.4.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 next
section, and then use: % cd /tmp
% unzip pdfClassesAndFonts_009e.zip -d /Library/WebServer/Documents/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 with pico 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.
C.4.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 to Chapter 13, and to use
the sample winestore application described in Chapter 16 to Chapter 20. In addition,
MySQL must be installed and configured before the winestore database
can be loaded.
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. Open Terminal, which is located in
Applications Utilities.
Maximize the Terminal window. In the Terminal window, log in as the
root user by typing: % su
Supply the password you set when unlocking the root user. Uncompress the winestore database by typing the
following % cd /tmp
% 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 -ppassword < /tmp/winestore.data
Be patient, this may take a while. After the loading is complete 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.
C.4.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.
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 Steps 2 and 3 in Section C.4.2. Open Terminal, which is located in
Applications Utilities.
Maximize the Terminal window. In the Terminal window, login as the
root user by typing: % su
Supply the password you set when unlocking the root user. Move the application into your Apache document root by typing into
your Terminal window: % mv /tmp/wda2-winestore.zip /Library/WebServer/Documents
Unzip the wda2-winestore.zip code in the
document root directory. This will create the subdirectory
wda2-winestore: % cd /Library/WebServer/Documents
% unzip wda2-winestore.zip
Edit the file wda2-winestore/includes/db.inc
using pico by typing: % pico wda2-winestore/includes/db.inc
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 by pressing ctrl-o and Enter.
Exit pico using ctrl-x. Edit the file
wda2-winestore/includes/winestore.inc by typing: % pico wda2-winestore/includes/winestore.inc
Locate the following three lines: // define("D_INSTALL_PATH", "c:/progra~1/easyph~1/www");
// define("D_INSTALL_PATH", "/Library/WebServer/Documents");
define("D_INSTALL_PATH", "/usr/local/apache2/htdocs");
Uncomment the second line and comment-out the third so that you have
the following: // define("D_INSTALL_PATH", "c:/progra~1/easyph~1/www");
define("D_INSTALL_PATH", "/Library/WebServer/Documents");
// define("D_INSTALL_PATH", "/usr/local/apache2/htdocs");
Save the file by pressing ctrl-o and Enter.
Quit the editor using ctrl-x. 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 /Library/WebServer/Documents/wda2-winestore
% chmod a+r /Library/WebServer/Documents/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.
|
No comments:
Post a Comment