Appendix A. Installation Guide
This
appendix is a guide to installing the
software used in the book. The first section presents the steps to
install and configure MySQL, Apache, and PHP under the Linux
operating system environment. We then present a short guide to
downloading and installing the PHP script examples used in this book.
The last major section shows how a secure Apache web server can be
installed using the Secure Sockets Layer library. We conclude with a
list of installation resources for Microsoft Windows, Linux, and
other environments.
A.1. Installing MySQL, Apache, and PHP
There
are three approaches to installing MySQL, Apache, and PHP:
-
Install a distribution of the Linux operating system that includes
the software as precompiled packages. This is the easiest approach.
-
Purchase or obtain an installation package; pointers to PHP Triad for
the Microsoft Windows environment, and NuSphere for most
platforms—including Linux and Sun Solaris—are included at
the end of this appendix. This is an easy approach.
-
Obtain and build the software from source code. This is the most
difficult approach, but it has the advantage that the latest software
is installed and the configuration layout and options are controlled
in the process.
This section focuses on the third approach, obtaining and building
the software from source code. Specifically, this section is a short
guide to installation under the Linux operating system, and the
result is an installation of Apache with PHP as a static
module and a complete MySQL installation. We
don't provide detailed information on the
configuration of the components, installation on other platforms, or
choices that can be made in installation. A short list of more
detailed installation resources is presented at the end of this
appendix.
Before we begin, several basic components are required:
-
An ANSI-compliant C programming language compiler such as
gcc; included in almost all Linux distributions
-
flex, the fast lexical analyzer, included in
almost all Linux distributions
-
bison, the GNU project parser generator; included
in most Linux distributions
-
Superuser, that is, root access to the Linux machine on which the
software is to be installed
-
Common Linux utilities such as gzip,
tar, and gmake
A.1.1. Installing MySQL
The instructions here are for installing MySQL 3. MySQL is bundled
with only some Linux installations. We assume that MySQL
isn't installed or, if it is installed, that a new
version is to be installed to replace the current installation.
-
Download the latest version of MySQL from http://www.mysql.com/downloads/mysql.html.
Choose the latest stable release and, from the stable release page,
choose the option under "Source
Downloads" marked "tarball
(.tar.gz)". Download the file into a directory where
files can be created and there is sufficient disk space. A good
location is /tmp. Change directory to this
location using:
% cd /tmp
Note that the % character should not be typed in;
this represents the Linux shell prompt and indicates that the command
should be entered at the shell prompt.
-
Uncompress the package in the new installation directory by running:
% gzip -d mysql-<version>.tar.gz
If MySQL 3.23.42 has been downloaded, the command is:
% gzip -d mysql-3.23.42.tar.gz
-
Un-tar the tape archive file by running:
% tar xvf mysql-<version_number>.tar
A list of files that are extracted is shown.
If the version downloaded is MySQL 3.23.42, the command is:
% tar xvf mysql-3.23.42.tar
-
Change directory to the MySQL distribution directory:
% cd mysql-<version>
If the version is MySQL 3.23.42, type:
% cd mysql-3.23.42
-
Add a new Unix group account for the MySQL files:
% groupadd mysql
-
Add a new Unix user who is a member of the newly created Unix group
mysql:
% useradd -g mysql mysql
-
Decide on an installation directory. Later, we recommend that PHP and
Apache be installed in /usr/local/, so a good
choice is /usr/local/mysql/. We assume
throughout these steps that /usr/local/mysql/ is
used; if another directory is chosen, replace
/usr/local/mysql/ with the alternative choice in
the remaining steps.
-
Configure the MySQL installation by running the
configure script. This detects the available Linux
tools and the installation environment for the MySQL configuration:
% ./configure --prefix=/usr/local/mysql
-
Compile the MySQL DBMS:
% make
-
Install MySQL in the location chosen in Step 7 by running the command:
% make install
-
MySQL is now installed but isn't yet configured.
Now, run the mysql_install_db script to
initialize the system databases used by MySQL:
% ./scripts/mysql_install_db
-
Change the owner of the MySQL program files to be the
root user:
% chown -R root /usr/local/mysql
-
Change the owner of the MySQL databases and log files to be the
mysql user created in Step 6:
% chown -R mysql /usr/local/mysql/var
-
Change the group of the MySQL installation files to be the
mysql group:
% chgrp -R mysql /usr/local/mysql
-
Copy the default medium-scale parameter configuration file to the
default location of /etc. These parameters are
read when MySQL is started. The copy command is:
% cp support-files/my-medium.cnf /etc/my.cnf
-
Edit the configuration file and adjust the default number of maximum
connections to match the default value for the maximum Apache web
server connections. Using a text editor, edit the file
/etc/my.cnf, and find the section beginning with
the following text:
# The MySQL server
[mysqld]
In this section, add the following line, then save the file, and exit
the editor:
set-variable = max_connections=150
-
The MySQL configuration is now complete, and MySQL is ready to be
started. Start the MySQL DBMS with the following command:
% /usr/local/mysql/bin/safe_mysqld --user=mysql &
-
Check that the MySQL DBMS is running with the
mysqladmin utility. The following command reports
statistics about the MySQL DBMS version and usage:
% /usr/local/mysql/bin/mysqladmin version
-
Choose and set a password for root user access to
the MySQL DBMS. To set a password of secret,
use:
% /usr/local/mysql/bin/mysqladmin -uroot password secret
Record the password for later use.
-
The MySQL server is currently running. However, when the machine is
rebooted, MySQL doesn't restart automatically.
After reboot, the command in Step 17 can be used to restart MySQL or,
alternatively, this process can be made automatic. To make the
process automatic, find the file rc.local
(normally either in or below the directory
/etc). This file is used to list locally
installed software that should be run on startup. Using an editor,
add the following line to the bottom of the
rc.local file:
/usr/local/mysql/bin/safe_mysqld --user=mysql &
The installation of MySQL is now complete.
These steps install MySQL and start the DBMS server but
don't configure a user or user databases. The steps
to add a user are the subject of the next section.
A.1.2. Configuring MySQL
The following steps create a user for the MySQL installation that is
used in PHP scripts to access the DBMS. The user can carry out all
actions required in Chapter 4 to Chapter 13 on the
winestore database but has no access to other
databases and can't change database access
privileges. In addition, the new user can't access
the DBMS from a remote server, under the assumption that the MySQL
DBMS and Apache are installed on the same machine through following
the instructions in this appendix.
The steps are as follows:
-
Check that MySQL is running using the password defined in Step 19 of
the MySQL installation instructions:
% /usr/local/mysql/bin/mysqladmin -psecret version
If it isn't, then log in as the
root user and start the MySQL DBMS using:
% /usr/local/mysql/bin/safe_mysqld --user=mysql &
-
Start the MySQL command line interpreter using the same password as
in the last step:
% /usr/local/mysql/bin/mysql -psecret
-
Add a new user to the user table in the
mysql database. Choose a username to replace
username and a password to replace
secret in the following command:
GRANT ALL PRIVILEGES ON winestore.* TO username@localhost
IDENTIFIED BY 'secret';
MySQL responds with:
Query OK, 0 rows affected (0.00 sec)
Record the username and password for use in the examples in Chapter 3 to Chapter 13.
-
Quit the MySQL command interpreter with the command:
quit
MySQL responds with:
Bye
-
Test the user created in Step 3 by running the MySQL command
interpreter using the username and password:
% /usr/local/mysql/bin/mysql -uusername -psecret
MySQL responds with a message beginning:
Welcome to the MySQL monitor.
-
Quit the MySQL interpreter again with:
quit
The MySQL DBMS is now configured with a user who can access the
winestore database from the database server
machine localhost. The
winestore database can't be
tested yet; the winestore database is loaded and
tested in Section 3.2 in Chapter 3.
A.1.3. Installing Apache
The
Apache web server is usually installed with most common Linux
installations. However, we assume that it isn't
installed or that an upgrade is required. In any case, it is
essential that the source of Apache is available so that it can be
recompiled to include PHP as a module.
If a current version is running, kill the process or stop the web
server by running the script apachectl stop,
usually found in the directory
/usr/local/apache/bin.
Here are the steps to install Apache:
-
Get the latest version of the Apache HTTP Server from http://www.apache.org/dist/httpd/.
Choose the latest source code version
ending in the suffix .tar.gz and save the file
in the /tmp directory. However, if a secure
Apache web server with SSL is required instead of the usual
installation, find out which is the latest version of Apache that has
SSL support by first following the instructions in the section
"Installing Apache and ApacheSSL,"
later in this chapter.
-
Move the Apache distribution file to the base directory of the
desired installation. The most common location is
/usr/local/ and, assuming the distribution
downloaded is Apache 1.3.20, and it was downloaded in the first step
into the /tmp directory, the command is:
% mv /tmp/apache_1.3.20.tar.gz /usr/local/
After moving the distribution to the desired location, change the
directory to that location using:
% cd /usr/local
-
Uncompress the package in the new installation directory by running:
% gzip -d apache_<version_number>.tar.gz
If the distribution downloaded is Apache 1.3.20, the command is:
% gzip -d apache_1.3.20.tar.gz
-
Un-tar the archive file by running:
% tar xvf apache_<version_number>.tar
The list of files extracted is shown.
If the version downloaded was Apache 1.3.20, then the command is:
% tar xvf apache_1.3.20.tar
-
Change directory to the Apache installation:
% cd apache_<version_number>
If the Apache version is 1.3.20, type:
% cd apache_1.3.20
-
Configure the Apache installation by running the
configure script. This detects the available Linux
tools, the installation environment, and other details for the Apache
configuration:
% ./configure --with-layout=Apache
-
Apache has not yet been compiled or installed. The next step is to
configure and build the PHP installation, and then to complete the
Apache installation. Go ahead to Step 1 in Section A.1.4, and return to Step 8 when
the PHP steps are complete.
-
The PHP module is now ready to be installed as part of the Apache web
server. The following command reconfigures Apache to activate the PHP
module support. However, the library referred to in the
activate-module command doesn't
yet exist (it is built in the next step):
% ./configure --with-layout=Apache --activate-module=src/modules/php4/libphp4.a
-
Compile the Apache web server using the command:
% make
-
Install the Apache server using the command:
% make install
If the installation of Apache with PHP support has been successful,
the following message is shown:
+---------------------------------------------------------+
+
|You now have successfully built and installed the |
|Apache 1.3 HTTP server. To verify that Apache actually |
|works correctly you now should first check the |
|(initially created or preserved) configuration files |
| |
| /usr/local/apache/conf/httpd.conf
| |
|
| and then you should be able to immediately fire up |
| Apache the first time by running: |
| |
| /usr/local/apache/bin/apachectl start
| |
| Thanks for using Apache. The Apache Group |
| http://www.apache.org/ |
+-------------------------------------------------------+
-
Edit the Apache configuration file and enable PHP script engine
support for files that have the suffix .php. To
do this, edit the file
/usr/local/apache/conf/httpd.conf and remove the
# character from the beginning of the following
line:
AddType application/x-httpd-php .php
After removing the comment character #, save the
file and exit the editor.
-
Start the Apache web server by running the command indicated by the
installation process in Step 10:
% /usr/local/apache/bin/apachectl start
After the Apache server starts up, the following is displayed:
/usr/local/apache/bin/apachectl start: httpd started
-
Check that the server is responding to HTTP requests by accessing it
using a web browser. The simplest way to check is to use a web
browser to load the URL http://localhost/. If Apache is serving
correctly, an Apache test page is shown; if a previously installed
Apache has been upgraded, another page may be displayed.
-
To test the PHP module, change the directory to the Apache document
root:
% cd /usr/local/apache/htdocs
-
Create a file with the name phpinfo.php using a
text editor. In the file, type the following, then save the script,
and exit the editor:
<? phpinfo( ); ?>
-
Test the newly created PHP script by retrieving with a browser the
following URL http://localhost/phpinfo.php.
A web page of information about the Apache and PHP installation is
shown. If the page isn't shown—and this is a
common installation problem—check that Step 11 of these
instructions was correctly completed. If a problem is found, edit and
correct the problem, and restart Apache with the following command:
% /usr/local/apache/bin/apachectl restart
-
Apache is now running and serving both static HTML and PHP scripts,
and this installation process is complete.
However, when the machine is rebooted, Apache will not be restarted
automatically. After reboot, the command in Step 12 can be used to
restart Apache or, alternatively, this process can be made automatic.
To make the process automatic, find the file
rc.local, normally either in or below the
directory /etc. This file is used to list
locally installed software that should be run on start up. Using an
editor, add the following line to the bottom of the
rc.local file:
/usr/local/apache/bin/apachectl start
If Apache needs to be stopped at any time, this can by achieved by
running:
/usr/local/apache/bin/apachectl stop
The installation of Apache, PHP, and MySQL is now complete.
Instructions to optionally install the winestore source code examples
can be found in the later section Section A.2.
A.1.4. Installing PHP
The instructions here are for installing PHP4. PHP is bundled with
most Linux installations. However, we assume PHP
isn't installed or, if it is installed, that a newer
version is required to replace the existing installation. If Apache
is being reinstalled, PHP needs to be reinstalled also.
Here are the steps to installing PHP:
-
Steps 1 to 7 of the Apache installation instructions should be
completed.
-
Get the latest version of PHP from http://www.php.net/downloads.php
.
Download the "Complete Source Code"
version into the /tmp directory.
-
Choose an installation directory. If the Apache installation was
begun in /usr/local/, the same location can also
be used for PHP. We assume in the following steps that the base
directory of the Apache installation and PHP installation are the
same. Move the PHP source code file to the base directory of the
desired installation. Assuming this is
/usr/local/ and, assuming the distribution
downloaded is PHP 4.0.6 and it was downloaded into the
/tmp directory, the command is:
% mv /tmp/php-4.0.6.tar.gz /usr/local/
After moving the distribution to the desired location, change
directory to that location using:
% cd /usr/local
-
Uncompress the package in the new installation directory by running:
% gzip -d php-<version_number>.tar.gz
If the version downloaded is PHP 4.0.6, the command is:
% gzip -d php-4.0.6.tar.gz
-
Un-tar the distribution by running:
% tar xvf php-<version_number>.tar
A list of files extracted is displayed.
If the version downloaded is PHP 4.0.6, the command is:
% tar xvf php-4.0.6.tar
-
Change directory to the PHP installation:
% cd php-<version_number>
If the version is PHP 4.0.6, type:
% cd php-4.0.6
-
Configure the PHP installation by running the
configure script. This detects the available Linux
tools, the installation environment, adds MySQL support, and prepares
for Apache integration. It assumes that MySQL has been installed
previously in the directory
/usr/local/mysql:
% ./configure --with-mysql=/usr/local/mysql --with-apache=../apache_<vers>
If Apache 1.3.20 is being used, type:
% ./configure --with-mysql=/usr/local/mysql --with-apache=../apache_1.3.20
-
Compile the PHP scripting engine by running:
% make
-
Now that the PHP scripting engine is built, install the PHP engine
using:
% make install
-
The PHP installation is almost complete. Now copy across the default
PHP configuration file to the default location, This file,
php.ini, contains the settings that control the behavior
of PHP and includes, for example, how variables are initialized, how
sessions are managed, and what scripting tags can be used. The
command to copy the file is:
% cp php.ini-dist /usr/local/lib/php.ini
-
Change directory to the Apache installation:
% cd ../apache_<version_number>
If Apache 1.3.20 is being installed, type:
% cd ../apache_1.3.20
-
The initial configuration of the PHP scripting engine module is now
complete. Return to Step 8 of the Apache installation procedure and
complete the installation of Apache, which includes a test of the PHP
module.
| | | 13.3. Searching and Browsing | | A.2. Installing the Winestore Examples |
Copyright © 2003 O'Reilly & Associates. All rights reserved.
|