Tải bản đầy đủ (.pdf) (5 trang)

PHP and MySQL Web Development - P167 doc

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (109.7 KB, 5 trang )

802
Appendix A Installing PHP and MySQL
If you move MySQL and intend to run the MySQL executable, mysqld,you must tell it
where everything is by supplying command line options. Use C:\mysql\bin\mysqld
help to display all options. For example, if you have moved the MySQL distribution to
'D:\programs\mysql',you must start mysqld with: 'D:\programs\mysql\bin\mysqld
basedir D:\programs\mysql'.
If you move it and are running it as a Windows service, you need to create an ini file
called my.ini and place it in your main Windows directory.Your ini file will have content
something like this:
[mysqld]
basedir=D:/programs/mysql/bin/
datadir= D:/programs/mysql/data/
In the NT/2000/XP setup, the name of the MySQL server is mysqld-nt, and it will
normally be installed as a service.A service is a program that runs constantly in the
background intended to provide services to other programs.They usually run automati-
cally when you start the machine, which will save you the effort of having to start them
each time.
You can install the MySQL server as a service by going to the windows command
prompt and typing this:
cd c:\mysql\bin
mysqld-nt –install
The response you should get is
Service successfully installed.
Now you can start and stop the MySQL service from the command line with:
NET START mysql
NET STOP mysql
Note the executable’s name is mysqld-nt, but the service’s name is just mysql. If you run
NET START mysql you should see the following message:
The MySql service is starting.
The MySql service was started successfully.


After the server has been installed, it can be stopped, started, or set to start automatically
using the Services utility (found in Control Panel).To open Services, click Start, point to
Settings, and click Control Panel. Double-click Administrative Tools, and then double-
click Services.
The Services utility is shown in Figure A.4. If you want to set any MySQL options,
you must first stop the service, and then specify them as startup parameters in the Services
utility before restarting the MySQL service.The MySQL service can be stopped using
the Services utility, or using the commands NET STOP MySQL or mysqladmin shutdown.
39 525x appA 1/24/03 3:38 PM Page 802
803
Installing Apache, PHP, and MySQL Under Windows
Figure A.4 The Services utility allows you to configure the
services running on your machine.
To test whether or not MySQL is working, you can execute the following commands:
C:\mysql\bin\mysqlshow
C:\mysql\bin\mysqlshow mysql
C:\mysql\bin\mysqladmin version status proc
The first command (mysqlshow) should give you a list of databases.When installed,
MySQL automatically creates two databases named mysql and test.The database mysql
will be used for storing the permissions and access to the server.The database test is
not required, but gives you a safe place to execute commands to see if things are config-
ured correctly.
The second command (mysqlshow mysql) will show you the tables in the mysql
database.
The third command (mysqladmin version status proc) will tell you about the
current status of MySQL.
The default configuration is not really ideal. There are a few loose ends we need to
attend to:
n
Setting your PATH

n
Deleting the anonymous user
n
Setting the root password
Setting Your PATH
MySQL comes with lots of command line utilities with varying degrees of usefulness.
None of these are easy to get at unless the MySQL binary directory is in your PATH.The
purpose of this environment variable is to tell Windows where to look for executable
programs.
Many of the common commands you use at the Windows command prompt, like
dir and cd,are internal and built into cmd.exe. Others, like format and ipconfig,have
their own executables. It would not be convenient to have to type C:\WINNT\
system32\format if you wanted to format a disk. It would not be convenient to have to
type C:\mysql\bin\mysql to run the MySQL monitor.
39 525x appA 1/24/03 3:38 PM Page 803
804
Appendix A Installing PHP and MySQL
The directory that the executables for your basic Windows commands, like format.exe,
reside in is automatically in your PATH, so you can simply type format. In order to have
the same convenience with the mysql command line tools, we need to add it.
Click Start, and choose Settings, Control Panel. Double-click System and go to the
Advanced tab. If you click the Environment Variables button, you will be presented with
a dialog box which allows you to view the environment variables for your system.
Double-clicking PATH will allow you to edit it.
Add a semicolon to the end of your current path to separate your new entry from
the previous one then add c:\mysql\bin.When you click OK, your addition will be
stored in the machine’s registry. Next time you restart the machine, you will be able to
type mysql rather than C:\mysql\bin\mysql.
Deleting the Anonymous User
The default configuration of MySQL allows any user access to the system without pro-

viding a username or password.This is obviously undesirable.
The first thing we want to do is delete the anonymous user. Opening a command
prompt and typing the following lines will accomplish that.
c:\mysql\bin\mysql
use mysql
delete from user where User='';
quit
c:\mysql\bin\mysqladmin reload
The anonymous user is now gone.
Setting the root Password
Even the superuser account, root, has no password yet.To set this user’s password type
these lines:
c:\mysql\bin\mysqladmin -u root password your_password
c:\mysql\bin\mysqladmin -u root -h your_host_name password your_password
You should find that tasks that previously required no username or password will now
fail without this information.Attempting to run
c:\mysql\bin\mysqladmin reload
or
c:\mysql\bin\mysqladmin shutdown
will now fail.
From now on, you will need to use the -u flag and provide a username, and the -p
flag to tell MySQL that you have a password, as in this example:
c:\mysql\bin\mysqladmin -u root -p reload
39 525x appA 1/24/03 3:38 PM Page 804
805
Installing Apache, PHP, and MySQL Under Windows
If you type this command MySQL should now prompt you for the root password that
you just set.
If you need more information, please refer to the MySQL Web site,
.

We are now ready to install Apache under Windows. Let’s begin!
Installing Apache Under Windows
Apache 1.3 and later is designed to run on Windows NT, 2000, and XP.The installer will
only work with the x86 family of processors, such as Intel’s. Apache also runs on
Windows 95, 98, and XP but these have not been tested. In all cases TCP/IP networking
must be installed. Make sure you use the Winsock 2 library if you decide to install it
under either Windows 95 or 98.
We downloaded this file:
apache_1.3.27-win32-x86-no_src.msi.
This file contains the current version (within the 1.3 hierarchy) for Windows, without
source code, packaged as an MSI file. MSI files are the package format used by the
Windows installer.
Unless you have a really elusive bug, or want to contribute to the development effort,
it is unlikely that you will want to compile the source code yourself.This single file con-
tains the Apache server ready to be installed.
Double-clicking the file you downloaded to start the process.
The installation process should look familiar to you. As shown in Figure A.5, it looks
similar to many other Windows installers.
Figure A.5 The Apache installer is easy to use.
The install program will prompt you for the following:
n
The network name, server name, and administrator’s email address. If you are
building a server for real use, you should know the answers to these questions. If
you are building a server for your own personal use, the answers are not particular-
ly important.
39 525x appA 1/24/03 3:38 PM Page 805
806
Appendix A Installing PHP and MySQL
n
Whether you want Apache to run as a service.As with MySQL, it is usually easier

to set it up this way.
n
The installation type.We recommend the Complete option, but you can choose
Custom if you wish to leave out some components such as the documentation.
n
The directory in which to install Apache. (The default is C:\Program
Files\Apache Group\Apache.)
After you choose all these options, the Apache server will be installed and started.
Apache will be listening to port 80 (unless you changed the Port, Listen, or
BindAddress directives in the configuration files) after it starts.To connect to the server
and access the default page, launch a browser and enter this URL:
http://localhost/
This should respond with a welcome page similar to that shown in Figure A.1, and a
link to the Apache manual. If nothing happens or you get an error, look in the
error.log file in the logs directory. If your host isn’t connected to the Internet, you
might have to use this URL:
http://127.0.0.1/
This is the IP address that means localhost.
If you have changed the port number from 80, you will need to append
:port_number on the end of the URL.
Note that Apache cannot share the same port with another TCP/IP application.
You can start and stop the Apache service from your Start menu: Apache adds itself
under Programs->Apache HTTP Server. Under the “Control Apache Server” heading
you will see that you can Start, Stop, and Restart the server.
After installing Apache, you might need to edit the configuration files that live in the
conf directory.We will look at editing the configuration file httpd.conf when we
install PHP.
If you need to enable Apache with SSL in Windows, you should follow the excellent
FAQ at
/>but be aware that it is not for the faint-hearted.

Installing PHP for Windows
There are a couple of different ways to do this.You can either install it manually, or use
the InstallShield installer.You have a choice of downloads at the PHP site.
Using the installer makes it amazingly easy and will give you a working PHP installa-
tion but with no modules installed. Installing manually is also pretty simple and gives you
a full set of modules.The choice is yours, but we recommend you use the manual
approach as you will need many of the different modules as you work your way through
this book.We will discuss both installations.
39 525x appA 1/24/03 3:38 PM Page 806

×