How to Install MySQL on Windows Vista and Configure PHP 5 to Use It

How to Set Up and Configure the MySQL Server with PHP 5 on Vista


How to Install MySQL on Windows Vista and Configure PHP 5 to Use It

by Christopher Heng, thesitewizard.com

The MySQL database server is used by many web applications to store its data. For example, most of the free PHP content management systems (CMSes) and free PHP blog scripts use it to store the content of the website (or blog). Its use is not restricted to such scripts, of course, and it can be used to store data for web surveys, forums and so on.

Since it is so widely used, many webmasters have asked me how they can install it on their own Windows computer so that they can test a local copy of their scripts and website before uploading it "live" on the Internet. This article gives you a step-by-step guide for setting up MySQL on Windows Vista.

(If you are a new webmaster trying to find out what MySQL is, please see the article What is MySQL? What is a Database? What is SQL? instead.)

Things to Note

Before you start, please note a few things:

How to Set Up MySQL

Before you begin, go to the MySQL download page, and click the link for the MySQL Community Edition (also known as "MySQL Community Server" elsewhere on the site). Look for the "Windows Essentials (x86)" package and download it. (Note: you may have to work a bit to find it: that is, scroll down pages, click links and whatnot.)

The installation itself is generally easy and fairly standard.

  1. Double-click the MySQL installer that you downloaded. Read the information displayed in the install screens and click the necessary buttons (eg, "Next"). When you come to a screen entitled "Setup Type", leave the radio button selected at "Typical" and click the "Next" button. The installer should display a summary of its settings. Click the "Install" button to let it proceed with the installation.

  2. Vista will issue a "User Account Control" dialog box, asking you for permission to let the installer do its job. Click "Continue".

  3. You may then get two dialog boxes with advertisements. Just click "Next".

  4. Finally, a "Wizard Completed" dialog box should appear. Uncheck the box "Configure the MySQL Server now" box. Don't worry, we'll do it manually from the Start menu ourselves. Then click the "Finish" button.

How to Configure the MySQL Server

Now that MySQL has been installed on your computer, you will need to configure it.

  1. Click the Start menu (the round button that has the Windows logo on the bottom left of your computer monitor). Type "MySQL" into the search field, and you should be able to see "MySQL Server Instance Config Wizard" highlighted at the top of the menu. Select it (if it's not already selected) and hit the ENTER key.

  2. Vista's User Account Control will appear, asking you for permission to let the program run. Click "Continue".

  3. The MySQL config wizard should appear. Click "Next" to go to the dialog box that lets you select the type of configuration you want. Select "Detailed Configuration" if it's not already chosen, then click "Next".

  4. The next screen lets you select a server type. Since you're just using MySQL to test your scripts, and you will be running your editor, browser, etc, on the same computer, you should probably select the "Developer Machine". This way MySQL does not eat up a lot of your system memory, allowing your other programs to run smoothly. Click "Next".

  5. Leave the default of "Multifunctional Database" selected in the window asking you about your "database usage", unless you know specifically how you're going to be using the database. Click "Next" when you're through deciding.

  6. The next screen in the dialog box lets you select the drive where your database is to be stored. If you have no particular preference, leave it at the default and click "Next".

  7. You will now need to set the number of concurrent connections that can be made to the MySQL server. In general, since you're only using the server to test your own scripts and you're the only one invoking those scripts, the default of "Decision Support (DSS)/OLAP" (20 connections) is probably more than enough. If this is not true, feel free to select one of the other options, or to manually set the maximum number of simultaneous connections. (Note: even if there are a few other people in your office or home helping you test your scripts, chances are that 20 connections is more than enough. If it isn't, you may need to rewrite your script so that it isn't quite so connection-intensive.) Click "Next" when you're through.

  8. In the next screen, leave the "Enable TCP/IP Networking" option checked. By default, MySQL will listen to connections made through port 3306 on your computer. Unless you know for sure that port 3306 is being used by another program, just leave it at the default. If you don't know what I'm talking about, leave it at the default.

    Tick the "Add firewall exception for this port". This will open up the port in Vista's firewall so that MySQL will be able to receive connection attempts made by other programs. If you use third-party firewalls or an antivirus program that includes a firewall, you will have to configure those firewalls to allow MySQL to receive connections yourself. (The exact method, unfortunately, differs from firewall to firewall, so I can't give a general procedure that works with every program.)

    WARNING: making this "exception" in Vista's firewall effectively opens up a hole in your computer. If your computer is connected to a network or the Internet, other computers will also be able to connect to your MySQL server. This is the reason why many web hosts only allow machines on their own network (and not just any computer on the Internet) to access their MySQL server. I will describe a way how you can restrict the connections to your own network later in this article.

  9. Leave "Enable Strict Mode" checked and click the "Next" button.

  10. The next screen lets you set the default way your data is stored in your database.

    If you're going to be using English, you can either leave the selection at "Standard Character Set" or choose "Best Support for Multilingualism". Otherwise, select "Best Support for Multilingualism". Alternatively, if you know what you're doing, check the "Manual Selected Default Character Set / Collation" and manually set the character set you want.

    When you're finished, click "Next".

  11. Make sure the "Install As Windows Service" option is checked in the next window that appears. Ignore the "Include Bin Directory in Windows PATH" (that is, leave it unticked). Click "Next".

  12. In the screen that asks you for the root password for your database, enter the password you want to use. Leave the first field, which asks for the current password, blank. (By default, there is no password.) Then type in the same password in both the "New root password" and the "Confirm" fields.

    Note that this is not the same as the password as the one you set for individual databases created for your scripts. This password gives you administrator access to everything, and lets you create users, grant user access rights and so on. If you're prone to forgetting passwords, you may want to write down the password somewhere.

    (For those who are curious, in computer lingo, a "root" user is basically the most powerful user on a system. It's sometimes called the "superuser" or "Administrator". Such a user has the permissions to do anything, even delete everything. You should always set a password for the root user.)

    Do not check the box "Enable root access from remote machines" unless you know what you're doing. Basically, as configured, the only way you can log in as "root" to your database is to do it from the computer you're installing MySQL on. If you tick that box, anyone connected to your machine (even over the network) will be able to log in as "root" if they know the password. If you do not check the box, even if your password is leaked, the hacker (or whatever) will need to have access to your computer to log in as root. Or at least that's the theory, anyway.

    For security reasons, do NOT check the "Create An Anonymous Account" box.

    Click "Next" when you're done with the passwords.

  13. Click "Execute" in the next window to let the wizard configure MySQL. When it is done, click the "Finish" button.

Adjusting the Vista Firewall Rules

By default, the MySQL configuration wizard opens a port in the Vista Firewall so that any computer on the Internet can access your MySQL server. Since this is just your test server, chances are that this is not what you want. You probably only want the scripts on your own computer, or perhaps on another computer on your intranet (your own office network or home network) to access it. This section describes how you can restrict access to port 3306 in the Vista Firewall to only machines in your own network. This does not mean that your server is now secure, but it should hopefully be slightly less vulnerable than the default set up by the wizard.

  1. Open the Control Panel. You can do this from the Start menu. Click the "Classic View" line in the left column. In the right column, scroll down to locate "Windows Firewall" and doubleclick it.

  2. Click the "Change settings" link in the Windows Firewall window. Vista's User Account Control dialog box will appear. Click "Continue".

  3. In the Windows Firewall Settings dialog box that appears, click the "Exceptions" tab (near the top of the dialog box).

  4. Scroll down the list in the "Program or port" box to locate "MySQL Server". Select it with one click, being careful not to uncheck the box. (If you accidentally unchecked it, just click it again to put the tick back.)

  5. Click the "Properties" button. The "Edit a Port" dialog box appears. Click the "Change scope" button in that dialog box.

  6. A new dialog box, "Change Scope", appears. The radio button "Any computer" should be currently selected. Click "My network (subnet) only" to select it. Click "OK".

  7. When you return to the "Edit a Port" dialog box, click "OK" to dismiss it.

  8. Finally, click "OK" in the "Windows Firewall Settings" to close it. (You will also probably want to close the Windows Firewall and Control Panel windows as well. Just click the "X" in the corner of those windows to get rid of them.)

Modifying Your PHP Configuration to Allow Your PHP Scripts to Use MySQL

Now that you have a MySQL server running on your machine, you will probably want to set up PHP so that your scripts can access databases on the server.

As mentioned earlier, I will assume that you have already set up PHP. If this is not true, please see my guide on this first.

  1. Open up your php.ini file in Notepad. If you have followed the steps in my guide, you should already be familiar with how to do this. The file itself can be found in c:\php\php.ini (unless you have installed it elsewhere).

  2. Look for the following line.

    extension_dir = "./"

    Modify it so that it now looks like this:

    extension_dir = "c:\php\ext"

    If you used my guide to set up PHP before, "c:\php\ext" is where the extensions were installed. Those who installed PHP in a different folder should of course put the correct path in the extension_dir setting.

  3. Now search for the following line:

    ;extension=php_mysql.dll

    (Be careful. It's surrounded by a number of lines that look very similar. Be sure you get the line that has "php_mysql.dll" and not "php_msql.dll", "php_mssql.dll" or "php_mysqli.dll".)

    Remove the initial semi-colon (";") so that the line now looks like this:

    extension=php_mysql.dll

    (A semi-colon indicates the start of a comment, which is ignored by the PHP interpreter. Removing it makes the line a configuration setting.)

  4. If you did not previously set the session path in php.ini, either because you didn't need to use sessions previously or because you read an earlier edition of my guide, please go back to the PHP 5 install guide and set the session path accordingly. (It's in the section entitled "Session Path".)

    (You don't need to do this if you know for sure that your script does not use sessions. However, if you use third party scripts that need a MySQL database, it will probably need session support.)

  5. Save the file and close Notepad.

  6. Now start up Windows Explorer. That is, click the Start menu, followed by "Computer". A window should open. Look for "System properties" somewhere near the top of the window. Click it. Then click "Advanced system settings" in the left column. The Vista User Account Control should appear. Click "Continue".

    In the "System Properties" dialog box that appears, click the "Environment Variables" button. In the list box under "System variables", look for the line that has "Path" in the first column. Click it to select it. Click the "Edit" button.

    A dialog box entitled "Edit System Variable" appears. Click somewhere in the "Variable value" line and use your arrow key to move to the end of the line (or just use the "End" key on your keyboard). Append the following:

    ;c:\php

    (Note: the above starts with a semi-colon and is followed by the directory/folder where you installed PHP.)

    This adds "c:\php" to the "PATH" environment variable, which is basically a list of directories that Windows searches for when it needs to look for a program or components of a program. You need to do this because PHP needs it to load a file called libmysql.dll, located in that directory. For some reason, it doesn't seem to be able to do it if "c:\php" is not in the PATH (even though it's the same directory as the PHP program itself).

    Once you have done this, restart your computer.

  7. After you reboot your computer, a simple PHP script like the following should be run to make sure that the PHP is able to load the MySQL libraries (DLLs).

    <?php phpinfo(); ?>

    Save the script as "test.php" in your "htdocs" directory and invoke it from your browser with "http://localhost/test.php". You should now be able to see a new section called "mysql" in the report. This means that PHP was successful in loading its MySQL-related libraries (the extension and libmysql.dll libraries).

Where to Go From Here

Now that you've installed MySQL, you may also want to install phpMyAdmin, a well-known PHP script that lets you administer your MySQL database server from a web interface. You can then create users, set permissions, create databases and tables, etc, from your web browser. (This is, of course, optional.)

Otherwise, you now ready to write and test your own PHP/MySQL scripts.

Copyright © 2009-2018 by Christopher Heng. All rights reserved.
Get more free tips and articles like this, on web design, promotion, revenue and scripting, from https://www.thesitewizard.com/.

thesitewizard™ News Feed (RSS Site Feed)  Subscribe to thesitewizard.com newsfeed

Do you find this article useful? You can learn of new articles and scripts that are published on thesitewizard.com by subscribing to the RSS feed. Simply point your RSS feed reader or a browser that supports RSS feeds at https://www.thesitewizard.com/thesitewizard.xml. You can read more about how to subscribe to RSS site feeds from my RSS FAQ.

Please Do Not Reprint This Article

This article is copyrighted. Please do not reproduce or distribute this article in whole or part, in any form.

Related Pages

New Articles

How to Link to This Page

It will appear on your page as:

How to Install MySQL on Windows Vista and Configure PHP 5 to Use It





Home
Donate
Contact
Link to Us
No Spam Policy
Privacy Policy
Topics
Site Map

Getting Started
Web Design
Search Engines
Revenue Making
Domains
Web Hosting
Blogging
JavaScripts
PHP
Perl / CGI
HTML
CSS
.htaccess / Apache
Newsletters
General
Seasonal
Reviews
FAQs
Wizards

 

 
Free webmasters and programmers resources, scripts and tutorials
 
HowtoHaven.com: Free How-To Guides
 
Site Design Tips at thesitewizard.com
Find this site useful?
Please link to us.