How’s “My First Web Server” treating you? Have you been playing around with making cool website places? Do you want me to just shut up and get on with the next part of the tutorial?
Well, it’s hard for me to explain what to do if I have to shut up, isn’t it? Enough jibber-jabber; let’s get on with it.
Part 3: The SQL Sequel
In order to have a really cool website place, you’ll need something to store lots of data in. That’s what a database is for, believe it or not. Almost every website on the Internet uses some sort of database, and almost all of those use some form of Structured Query Language, or SQL (pronounced “sequel”). Modern smartphones all have a SQL database on them, too (iPhones and Android phones really aren’t that different). The most popular SQL database for websites is called MySQL, and the best thing about it is that it’s free! Almost definitely the webspace you bought as part of the first section of this tutorial includes a MySQL database with it, but you need one on your development environment so you can get a cool website set up.
Head over to http://www.mysql.com/downloads/installer
and download the latest version of the MySQL installer package. When it asks you to log in you can just say “No thanks, just take me to the downloads.” You should then see a list of US mirrors. It doesn’t really matter which mirror you pick (they’re just different places you can download the file from). Click the little “http” next to the closest one to wherever you are. It’s a couple hundred megabytes, so it might take a while to download.
While you’re waiting for it to download, why not read some funny stuff on the Internet? You can pick up the rest of this tutorial when it’s done downloading. I’ll wait.
It’s done? You’re back? Cool. Install that thing you just downloaded.
The process is a bit more automated than the whole “just put these files somewhere” method that PHP uses. Select “Install MySQL Products” (duh). Accept the license terms and press Next. If you just downloaded the file you can probably skip the “Find Latest Products” step, but there’s no harm in it, really.
For “Setup Type” pick “Server only.” The other types install a bunch of additional stuff that we won’t need if all we want to do is website. If you’re thinking you might make some C++ applications or you otherwise need some ODBC connections, go ahead and pick “Developer Default.” If you don’t know what any of that means, just pick “Server only” please. The default Installation and Data paths should be perfectly fine.
My computer didn’t need any additional requirements, but yours might - it depends on how many C++ redistributables you have installed (among other things). Let the thing do it’s thing and get all of its beeps and boops in order before you continue.
You should just have the one Product to install. Make sure you gird your loins, and then press EXECUTE! The thing will install, it will be very anti-climactic, and then you’ll hit Next (twice).
Ensure that it’s set to be a Developer Machine, so MySQL won’t take over all of your memories.
Just use the default settings for Port Number. You can turn the Windows Service off, because you won’t be needing it. Security isn’t a huge concern because this is just going to run on your computer, so just make your password something really easy to remember, like “password.” It really doesn’t matter at this stage (just make sure you remember what you made it). Hit next a couple times until you can hit finish, and then hit that.
So now you have a database running on your computer. You’ll hardly be able to find proof of this, but just trust me. Before we can really do anything with it, we’ll need to download a really great tool called PHPMyAdmin. It’s a whole website that you’re going to run on your computer that connects to your MySQL database using PHP so you can create databases, manipulate tables, or do whatever you might want to do. It’s going to utilize everything we’ve done up to this point, so hopefully you were able to get everything working properly.
Head over to http://www.phpmyadmin.net/home_page/downloads.php
and pick the file called phpMyAdmin-X.X.X-english.zip (where the X’s are the latest version). Right now (as shown in the screenshot above), the file we want is the last one in the recommended version list. I guess you can get the “all languages” version if you want to manage your MySQL database in French or something.
Just like we did with PHP, you’re going to open up this zip file and extract it somewhere. Inside the file should just be one folder, named the same as the zip file itself.
Copy that folder to the directory where your Default Web Site is located (usually C:/inetpub/wwwroot). Once it’s done, rename the folder “phpMyAdmin” (that way it’s easier to access).
Inside this new phpMyAdmin folder, create a new folder called “config.” PhpMyAdmin needs this folder to save its various beeps and boops in as it works.
Right click the “config” folder, select “Properties,” and then go to the “Security” tab.
Press “Edit,” select “Users,” and then check the box under “Allow” for “Full control.” Do the same thing for IIS_IUSRS for good measure. This will make sure that phpMyAdmin can do whatever it wants to this folder. Press OK to save the security settings, and then OK again to close the Properties dialog box.
Now you have to go back to your php.ini file and make sure the MySQL extensions are activated. Open php.ini in notepad (it should be in C:phpphp.ini) and find the lines “;extension=php_mbstring.dll,” “;extension=php_mysql.dll” and “;extension=php_mysqli.dll.” Remove the semicolons from those lines (if there are any). Note that there are three extensions that you're enabling, here.
Now find the setting for extension_dir, and remove the semicolon from the line that says “extension_dir = ‘ext’” (or whatever it says under “On Windows”). Now save and close the file.
You will now probably need to recycle your Application Pool for any changes to the php.ini file to go through. In the IIS Manager (type “inetmgr” into the Run dialog), select “Application Pools” under “Connections,” and then right click on “DefaultAppPool” and say “Recycle.” Now PHP should be able to connect to your MySQL database.
Now you can point your browser to “localhost/phpMyAdmin” to get to the phpMyAdmin login. You’re telling your browser to open the “phpMyAdmin” folder inside the Default Web Site, and it then calls for “index.php” by default. This is a new website you installed inside your Internet. You’re really just going to town, making websites all over the place, now.
You might have tried to log in to phpMyAdmin with the username “root” and the password you specified when you installed MySQL. You showed good initiative, that’s for sure, but we’re not quite ready to go to there just yet. We have to actually start your MySQL server, and tell phpMyAdmin how to connect to it.
First you have to find your MySQL server bin directory. For me it’s C:/Program Files/MySQL/MySQL Server 5.5/bin. Just go to there, and open the file mysqld.exe. It should pop up a window which will then disappear. That’s it!
You can check to see if the server is running in Task Manager (right click on the taskbar and select “Start Task Manager.” If you can find “mysqld.exe” inside the Processes tab, your MySQL server is running! You can select it and say “End Process” to shut it down when you don’t need it. That will free up a bit of your precious memories if you need more memories.
Go to “localhost/phpMyAdmin/setup” in your browser to set up phpMyAdmin. It’s this kind of super complicated stuff that I had to go to College to learn. You’ll see at this point that there are no configured servers. You can tell that because it says “There are no configured servers” right there. We better configure ourselves a server.
Press “new server.” Leave everything as it is except for one setting. Under “Server configuration” check “Allow logins without a password.” Press “save.” You’ll see a message that Allow logins without a password causes security risks, but you don’t have to worry about that. Only you will have access to this, so you don’t have to worry so much about security for now. Hit the “Save” button at the bottom of the Overview page.
Now there should be a config.inc.php file inside that config folder. Move it out to the phpMyAdmin folder, and then delete the config folder. It is no longer necessary.
Now the time has come to login to phpMyAdmin. Go back to localhost/phpMyAdmin and log in with the username “root” and no password. If everything went as it was supposed to, you should now be logged in.
We’re now officially ready to host almost any kind of website you can create. We have PHP support and a fully armed and operational MySQL server. Next time we’ll get started setting up your actual website. This is where it gets fun!