<<

. 95
( 132 .)



>>

ting the most current download available from the Web site.
You might also need to view any updated installation instruction files.

NuSphere
The NuSphere Corporation first got into the MySQL/PHP world by offering a trans-
actional table for MySQL called Gemini. At the time of this writing, it™s difficult to
find any mention of Gemini on the NuSphere Web site. Instead, NuSphere seems to
be concentrating its efforts on a PHP integrated development environment (IDE)
called PHPed. (Incidentally, if you™re on Windows or Linux, you might want to
check this product out; it™s pretty cool.)
At the time of this writing, NuSphere continues to make a very nice Web-based
installer that installs PHP, MySQL, Apache, and mod_perl on Windows and Linux
systems. All you really have to do is double-click the install file, and NuSphere did
the rest.
It™s entirely possible that NuSphere will no longer offer this installer by the time
you read this book. Check its Web site (http://www.nusphere.com/cgi-bin/
nsp.cgi/custsrvc/utils/free_download.htm) to see what™s currently available.



Another installer, called Sokkit (formerly PHPtriad), used to be free for all
but now is being re-written as part of a commercial effort.




Installing on Windows from assorted binaries
You can install all these packages separately and in the process let them know how
to work together. We recommend getting the most recent binaries from the Web
sites of the organizations that distribute the software. These packages are con-
stantly updated, and there™s no reason not to have access to the most recent features.
(Of course, if you already installed these packages using phpdev or by means of
some similar arrangement you should skip to the section on “PHP Configuration.”)
Appendix C: Brief Guide to MySQL/PHP Installation and Configuration 573

Start by copying the MySQL binaries from the http://mysql.com/downloads
site to your local drive. Do the same for Apache and PHP (the appropriate download
sites here are http://httpd.apache.org/download.cgi and http://www.php.
net/download). The names of the files will be something like the following (they
may be slightly different, depending on the version you are using):

— mysql-4.0.14b-win.zip

— apache_1_3_22_win32_no_src.exe

— php-4.2.2-Win32.zip

Start by unzipping the MySQL file and PHP files with your favorite unzip tool.
(If you don™t have one, we recommend WinZip at http://www.winzip.com/.)
Unzip them into a directory you find convenient. We prefer using a separate direc-
tory for each.
Start with MySQL.

1. In the directory in which you unzipped the file, you will have a file
named setup.exe. Execute that file.
2. Choose a directory (for example, c:\mysql) in which you want to install it,
and then in the next screen, select a Typical installation. (You might want
to examine the custom options, but with the Windows installation very
few real options exist.)

At this point your MySQL installation is complete. To test it, go to the DOS
prompt and move to the directory you specified for your MySQL installation. Then
move to the subcategory \bin. If you then type mysqld, the MySQL daemon should
start. To test if your daemon is working, start up the MySQL command-line client
by typing mysql.
Next, you should install Apache.
This installation requires little more than double-clicking the executable you
copied from the apache.org site. The installation is pretty easy: all you really need
to do is select a domain name (just use localhost if you™re not actually putting it
live on the Internet) and a directory in which you would like to install Apache.
When the installation is completed an Apache HTTP Server group item is added to
the Start menu. It™s important to remember the directory in which you installed
Apache. That is where you™ll be putting all the PHP files that make up the applica-
tions. If you used the default settings, your default serving directory will be
c:\Program Files\Apache Group\Apache\htdocs.


Don™t start up Apache just yet. A little more configuration information
follows.
574 Part V: Appendixes

Now on to PHP. You should have a folder into which you unzipped all the PHP
files. (In the following instructions we are assuming the folder is c:\php.) Also, PHP 4
and later versions have a pretty good Apache module for Windows. In the previous
version of this book we recommended using the CGI binary. The Apache module
has a bit more in the way of functionality, so you should probably use that.

1. Copy php5ts.dll and php5apache.dll from c:\php into the c:\windows\
system or c:\winnt\system32 directory, whichever is available on your
version of Windows.
2. Next, copy the php.ini-dist file from the c:\php directory to c:\windows
on Windows 95/98, or c:\winnt or winnt40 on NT/2000/XP. Rename the
file php.ini. Now open the php.ini file and change the extension_dir entry
so it matches the name of the folder where you placed the .dll files. For
example:
extension_dir = c:/windows/system32

3. Now you need to alter your Apache configuration file. The easiest way
to do this is to go to the Start menu and select Apache HTTP Server ’
Configure Apache Server ’ Edit Configuration File.
4. Add the following three lines to the file. Note that the first line must
match the name of the directory on your system:
LoadModule php5_module c:/windows/system
AddModule mod_php5.c
AddType application/x-httpd-php .php

The last line ensures that all files with .php extensions are processed as
PHP applications. If you want other file extensions to by parsed by PHP,
simply add another AddType line to the conf file, as follows:
AddType application/x-httpd-php5 .phtml

You may have to make a couple of other alterations to your httpd.conf file, such
as the following:

— If the server refuses to start, you may need to add something to the
ServerName directive. If you are using TCP/IP in your local area network
you may need to add the IP address of your machine, as follows:
ServerName 192.168.1.2

Or, if your machine is not networked, you may want to use the following
ServerName:

ServerName 127.0.0.1
Appendix C: Brief Guide to MySQL/PHP Installation and Configuration 575

— If you also have Microsoft Personal Web Server running on your machine
you might want to change the port on which Apache runs. By default Web
servers listen on port 80, but you can change that by altering the port
line in httpd.conf to something else ” perhaps 8080.

And that should do it. Start Apache through the Start Menu. Add a file to your
\htdocs folder that contains the phpinfo() function. When you call that function
you should see that everything is working properly and that an entry for MySQL is
there.
Note that you don™t need to make any alterations to the php.ini file to make PHP
work with MySQL. In fact, MySQL support is built into PHP for Windows.


If you uncomment the directive extension=php_mysql.dll you will
have all kinds of problems getting a PHP page to load.




These are the basics you need to get going with PHP and MySQL on Windows.
Note that you can also install PHP as an ISAPI filter for Internet Information Server
(IIS) and PWS. The instructions for doing so are included in the readme.txt file
included in the PHP Zip file.


As of this writing, running PHP as an IIS filter is tricky and unreliable and not
recommended for a production environment. It™s better to associate the .php
extension with the PHP interpreter in the Internet Services Management
console. It™s much more reliable that way.




Installation on Unix/Mac OS X
On Unix, there are far more options that you might want to avail yourself of. You
might want to install by compiling the source code yourself or (on Linux) by using
.rpm files. This appendix covers only compiling from source. We strongly recom-
mend that you do not use .rpm files. The convenience that .rpms sometimes offer
does not extend to this type of configuration, largely because configuration can be
tricky and manual work is the only way to get it right.
You can compile a variety of libraries and optional functions into PHP, and
additional libraries and functions are being added all the time. In this quick guide,
we cover only some highlights.
576 Part V: Appendixes

If you have other priorities, need .rpms, or want to include options not covered
here, seek out the documentation in the online manuals. This really isn™t a very dif-
ficult installation, and you should be able to customize as you see fit with minimal
effort. First stop, MySQL.

MySQL installation
An option we have yet to discuss ” and probably the best one for Unixes ” is to get
a set of binaries distributed by MySQL AB. If you go to www.mysql.com/downloads
you can see binaries for about every major Unix distribution, including Solaris,
Irix, HP-UX, FreeBSD, and Mac OS X. It would be impractical for us to include all
these install files on the CD (and you™re better off getting them from the site any-
way), and the installation instructions can differ slightly from platform to platform.
Installing from binaries, however, is exceedingly easy ” and far quicker than com-
piling from source. If you download binaries for your platform you will see a set of
instructions that comes with the package. You can have MySQL installed in under
10 minutes after running only a handful of commands.
Complete information on MySQL installation can be found in Chapter 2 of the
MySQL online manual: http://www.mysql.com/documentation/mysql/bychapter/
manual_Installing.html. Check it out if you are having problems.
If you decide that you do want to install from source, you need to get a com-
pressed tarball of the source (a .tar.gz or .tgz file) from http://www.mysql.com/
downloads/. Copy it to a directory you want to work in and then unpack it with a
command like the following:

gunzip mysql-4.0.12.tar.gz
tar xf mysql-4.0.12.tar

This command creates a directory with the name of the MySQL distribution (for
example, mysql-4.0.12). Use cd to move into the directory. Note that the exact ver-
sion may be different, depending on when you download the software.
The first step is to run configure. You can set many options with configure
flags; to get a complete list run ./configure --help.
In the installations we™ve run, we have found it convenient to specify --prefix.
If you do not specify a prefix, /usr/local is used, and this is almost always perfectly
fine. Additionally, MySQL enables you to specify the location of any of the subdi-
rectories (the data directory, the bin directory, and so on). Usually that will not be
necessary. Normally you can run the following:

./configure --prefix=/path/to/installation

Now you have only two commands to execute:

make
make install
Appendix C: Brief Guide to MySQL/PHP Installation and Configuration 577

Note that you™ll probably have to run the make install command as root. Either
use su to switch to root, or, on platforms that support sudo, use that. The next thing
you want to do is cd into the /bin directory and run the following command, which
creates your default databases and permissions tables:

./mysql_install_db

You don™t want to have to run the MySQL daemon as root. You™re better off
making a user and group specifically for running the daemon, mainly because your
systems will be neater if you distribute responsibilities across users. Assign permis-
sions to directories that allow the MySQL user to access everything he or she needs.
In the following shell commands, we are creating a user and group named mysql
and then assigning proper rights to that user; we™re assuming an installation direc-
tory of /usr/local/mysql. These actions must also be performed as root.

shell> groupadd mysql
shell> useradd -g mysql mysql
shell> chown -R root /usr/local/mysql
shell> chown -R mysql /usr/local/mysql/var
shell> chgrp -R mysql /usr/local/mysql

At this point a directory listing of /usr/local/mysql should look about like this:

shell> ls -Fla

drwxr-xr-x 13 root mysql 442 Jun 26 13:31 ./
drwxr-xr-x 4 root wheel 136 Jun 26 13:28 ../
drwxr-xr-x 40 root mysql 1360 Jun 26 13:29 bin/
drwxr-xr-x 3 root mysql 102 Jun 26 13:28 include/
drwxr-xr-x 3 root mysql 102 Jun 26 13:28 info/
drwxr-xr-x 3 root mysql 102 Jun 26 13:28 lib/
drwxr-xr-x 3 root mysql 102 Jun 26 13:29 libexec/
drwxr-xr-x 3 root mysql 102 Jun 26 13:29 man/
drwxr-xr-x 9 root mysql 306 Jun 26 13:29 mysql-test/
drwxr-xr-x 3 root mysql 102 Jun 26 13:29 share/
drwxr-xr-x 25 root mysql 850 Jun 26 13:29 sql-bench/
drwx------ 15 mysql mysql 510 Aug 12 15:44 var/

You should now be able to start the mysql daemon using the mysqld_safe
command from the /bin directory. With the permissions you™ve created you need to
run the startup command as root while specifying that the daemon run as the user
named mysql:

sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &
578 Part V: Appendixes

By default MySQL uses port 3306 and keeps the all-important socket file at /tmp/
myslq.sock. This is generally okay: PHP looks for the socket file in this location.
However, if you have multiple installations of MySQL you need to change the port
and socket location, which can be a pain. You need to play with your my.cnf file.
See Chapter 4 of the MySQL manual for more information.

PHP/Apache
On Unix, PHP is loaded as an Apache module. Thus, the installation of the two

<<

. 95
( 132 .)



>>