Post-Installation Setup Tasks
No matter which operating system you're running, once PHP is installedand the MySQL server is in operation, the very first thing you need to do
is assign a root password for MySQL. MySQL lets only
authorized users view and manipulate the information stored in its databases,
so you'll need to tell MySQL who is an authorized user, and who isn't. When
MySQL is first installed, it's configured with a user named root that
has access to do pretty much any task without even entering a password. Your
first task should be to assign a password to the root user so that unauthorized
users can't tamper with your databases.It's important to realize that MySQL, just like a Web server or an FTP
server, can be accessed from any computer on the same network. If you're working
on a computer connected to the Internet that means anyone in the world could
try to connect to your MySQL server! The need to pick a hard-to-guess password
should be immediately obvious!To set a root password for MySQL, type the following command in the bin directory
of your MySQL installation:
mysql -u root mysql
This command connects you to your newly-installed MySQL server as the root user,
and chooses the mysql database. After a few lines of
introductory text, you should see the MySQL command prompt (mysql>).
To assign a password to the root user, type the following
three commands (pressing Enter after each one):
mysql>SET PASSWORD FOR root@localhost=PASSWORD("new password");
Query OK, 0 rows affected (0.00 sec)
mysql>SET PASSWORD FOR root@"%"=PASSWORD("new password");
Query OK, 0 rows affected (0.00 sec)
mysql>FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
Be sure to replace both instances of new password with
the password you want to assign to your root user. The
first command sets the password required when connecting from the machine
on which the server is running; the second sets the password for all other
connections.With that done, disconnect from MySQL with the quit command:
mysql>quit
Bye
Now, to try out your new password, at the system command prompt again,
request that the MySQL server tell you its current status:
mysqladmin -u root -p status
Enter your new password when prompted. You should see a brief message
that provides information about the server and its current status. The -u
root argument tells the program that you want to be identified
as the MySQL user called root. The -p argument
tells the program to prompt you for your password before it tries to connect.
The status argument just tells it that you're interested
in viewing the system status.If at any time you want to shut down the MySQL server, you can use the
command below. Notice the same -u root and -p arguments
as before:
mysqladmin -u root -p shutdown
With your MySQL database system safe from intrusion, all that's left
is to configure PHP. To do this, we'll use a text file called php.ini.
If you installed PHP under Windows, you should already have copied php.ini into
your Windows directory. If you installed PHP under Linux using the instructions
above, you should already have copied php.ini into the
PHP lib folder (/usr/local/php/lib),
or wherever you chose to put it.
Mac OS X distributions of PHP don't come with
a php.ini file by default; you can usually just let it
use its own default settings. If you're happy to do this, you can go ahead
and skip the rest of this section. If not, you can pinch a copy of php.ini-dist from
the Windows Binary distribution at http://www.php.net/,
rename it to php.ini, and place it in /usr/local/lib (which
you may have to create).
Open php.ini in your favourite text editor and
have a glance through it. Most of the settings are pretty well explained,
and most of the default settings are just fine for our purposes. Just check
to make sure that your settings match these:
register_globals = Off
magic_quotes_gpc = On
doc_root = the root document folder of your Web server[6]
extension_dir = the directory where you installed PHP[7]
Save the changes to php.ini, and then restart your
Web server. To restart Apache under Linux, log in as root and
type this command:
shell#apachectl graceful
You're done! Now you just need to test to make sure everything's working
(see "Your First PHP Script").[6]The "root document folder" of a Web server is the folder on the server computer where you must place a file to make it available in the root of your Website. On IIS servers, this is usually c:\inetpub\wwwroot, unless you have specifically set it to something else. On Apache servers, this is often the htdocs folder in the Apache installation directory unless you set it to something else yourself. Many Unix distributions use other locations when installing their packaged version of Apache; examples include /var/www and /home/httpd.[7]Usually c:\php on Windows, and /usr/local/php on Unix.