by Kevin Yank of SitePoint.com
Post-Installation Setup Tasks
Once PHP is installed and the MySQL server is running, whether you're running under Windows or Linux or some other operating system, the very first thing to be done is to assign a "root password" for MySQL. MySQL only lets authorized users view and manipulate the information stored in its databases, and it's up to you to make sure that MySQL knows who is an authorized user and who isn't. When MySQL is first installed, it is configured with a user named "root" that has access to do pretty much anything without even entering a password. Your first task should be to assign a password to the root user so that not just anyone can go messing around in 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 that 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 (include the quotes):
mysqladmin -u root password "your new password"
To make sure MySQL has registered this change, you should tell it to reload its list of authorized users and passwords:
mysqladmin -u root reload
If this command gives you an error message telling you that access was denied, don't worry. It just means the password has already taken effect.
To try out your new password, you can request that the MySQL server tell you about its current status:
mysqladmin -u root -p status
Enter your password when prompted. You should see a brief message showing some 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 trying 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 following command. 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. PHP is configured using 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 installation folder (/usr/local/php
).
Open php.ini
in your favorite 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 with the following:
magic_quotes_gpc = On
doc_root = <the document root folder of your Web server>
extension_dir = <the PHP install directory>
If you're running PHP version 4.0, you'll also need to check the following line:
register_globals = On
And if you're running PHP version 3.0 under Windows, uncomment the following line by removing the semicolon at the start of it (PHP 4.0 doesn't need this):
extension=php_mysql.dll
Save the changes to php.ini
, then restart your Web server. Under Linux, you can restart Apache if you're logged in as root by typing:
/etc/rc.d/init.d/httpd restart
You're done! Now all that's left is to test to make sure everything's working okay (see Your First PHP Script).
If Your Web Host Provides PHP and MySQL |
SitePoint.com is a fast growing Web Developer Community. Kevin Yank is the Editor of the SitePoint TechTimes, a fresh, technically oriented newsletter for the serious Webmaster. |