Friday, 19 April 2013

Install MySQL on IIS7 Server 2008

Now that you have installed PHP on your server, most of the popular PHP applications like WordPress & Joomla will require a database on the backend to support them.
While there are other options, MySQL is usually the database of choice to use for these applications. It is one of the most widely supported databases so you can usually find help if you run into a snag.
In this article we will install MySQL 5 on a Windows Server 2008 running IIS7.

How to Install MySQL on IIS7

As of this writing the current production version of MySQL is 5.0 Community, so that is what we are going to use for this example. We are also going to use the installer package, which can be downloaded at the following location:
In this case we are going to use the 32-bit "Essential" binary which is recommended for most users, so I am going to go ahead and have that downloaded onto our test machine and then we will get going.
1. Find where you downloaded the file and click on the .msi file.
Install MySql on IIS7 Server 2008 - 1
2. At the setup wizard click Next.
Install MySql on IIS7 Server 2008 - 2
3. I am going to choose the Typical install and then click Next.
Install MySql on IIS7 Server 2008 - 3
4. Review your chosen options then click Install.
5. Next you will see an advertisement to upgrade to MySQL Enterprise version. For some that is a good option as you get quite a bit of benefit from having the service relationship in place compared to the community addition.
You can read the ad or click for more information, but if you want to continue installing the software click Next
Install MySql on IIS7 Server 2008 - 5
6. Now you will see an advertisement for their monitoring service to keep a professional eye on your database. If you have a need for such service I encourage you to click the More button, but otherwise click Next.
Install MySql on IIS7 Server 2008 - 6
7. You should now arrive at the Wizard Completed window. Leave the box Configure the MySQL Server now checked and click on Finish.
Install MySql on IIS7 Server 2008 - 7
8. Now we will see the MySQL Server Instance Configuration Wizard, which will walk you through configuring your MySQL installation. Go ahead and click Next.
Install MySql on IIS7 Server 2008 - 8
9. In the next screen we will see two different options Detailed & Standard, I am going to go ahead and select the Detailed and click Next.
Install MySql on IIS7 Server 2008 - 9
10. The MySQL Instance Configuration screen is next, you have three options:
  • Developer Machine — Many other apps will be running on this machine and MySQL should use a minimal amount of memory.
  • Server Machine — Server apps will be running, this is the setting to use for web servers, MySQL will use a medium amount of memory.
  • Dedicated MySQL Server Machine – The big papa of installation choices, MySQL will be the only application on this server and will utilize all available memory.
We are going to go ahead and choose Server Machine for this demo, then click Next.
Install MySql on IIS7 Server 2008 - 10
11. Now we have to select the database usage. There is a lot that can be said for this but I am going to give you a quick summary:
The choices here boil down to what you are going to be using the database for and what feature set you need. The main difference between the MyISAM and InnoDB is speed and reliability. If you need transactional support you should know it and you would know to select Transactional Database to use InnoDB and use that.
In our demo we are going to use the Multifunctional Database to give us the greatest flexibility. After selecting that click Next.
Install MySql on IIS7 Server 2008 - 11
12. On the next windows you choose the place to put the InnoDB datafile.
If you have a raid or array storage you may want to move it there for performance/reliability reasons, but for this demo we will use the default and click Next.
Install MySql on IIS7 Server 2008 - 12
13. The next decision to make is how many connections to set the server up for.
Since this is going to be on a web server I am going to set it up to use 500 active connections at one time by selecting Online Transaction Processing (OLTP), but note that you can also setup a custom number by using the Manual Setting.
If I was working on a development box I would have probably selected Decision Support as that assumes 20 connections and would be ideal for just test purposes. After you make your decision click Next.
Install MySql on IIS7 Server 2008 - 13
14. This next screen is very important because it sets how other applications will connect to your MySQL instance.
The default port is 3306 and it is recommended that you leave this as is because it is the assigned port and most 3rd party applications you use will try to connect on that port. Now if you are coding your own application and can customize the port the application will use, then you could change the port.
You can also add a firewall exception by checking the box next to the port number. This is tricky depending on how your environment is going to be setup. I am going to add the exception for this demo but you may want to be more restrictive and only open the exception to the servers that would be connecting to the MySQL apps.
Enable Strict Mode is another added feature to MySQL 5 and it is recommended to leave it on. This basically does some data checks and forces applications to use correct formats.
Note: This may break some legacy apps that used older MySQL versions, but it is more preferable to patch those apps and keep this mode enabled.
After making your selections click Next.
Install MySql on IIS7 Server 2008 - 14
15. Now we will set the default character set that the database will use.
Again this will really be dependent on what your environment is, but for this demo we are going to use Best Support for Multilingualism as that supports most languages. If you know you are going to be using a specific set than you can also set that by using the Manual option.
After you are done go ahead and click Next.
Install MySql on IIS7 Server 2008 - 15
16. The next screen will setup MySQL to run as a service so if there are any reboots the database will come back up automatically. You can also set the Service name which is useful if you have more than 1 instance of MySQL running.
You can also select Include Bin Directory in Windows Path to add the server/client variables into the PATH variable. This is useful if you will be working from the command line for any reason.
For this demo we are going to select it and then click Next.
Install MySql on IIS7 Server 2008 - 16
17. Now let’s set a root password for the MySQL server instance. Type it in twice to confirm it, but leave Enable root access from remote machines unchecked unless you know you will need that.
Also leave Create An Anonymous Account unchecked as that could cause security issues.
Install MySql on IIS7 Server 2008 - 17
18. Finally we arrive at the final configuration window. All that is left is to click on Execute to setup the MySQL instance. Go ahead and click … you know you want to!
Install MySql on IIS7 Server 2008 - 18
19. You will see a brief summary at the end of the install that will let you know everything completed successfully and ask you to click Finish.
Now that you have a powerful database like MySQL installed on you server it gives you quite a few options for some great open source apps when combined with PHP and other programming languages.
My next article will be how to use some graphical applications to manage your MySQL databases.
Want to start working as a DBA? Check out our SQL 2012 Administration Essentials videos, and sign up for a 3-day free trial to access all of our courses!

Thursday, 18 April 2013

Setting up AWStats on Windows Server and IIS

Setting up AWStats on Windows Server and IIS

When it comes to gathering statistics on web sites, you can never have enough. While one of the most popular method for tracking statistics is through services such as Google Analytics, log file analysis remains a reliable way to track your visitors as they are immune to script blockers. A widely used tool for log file analysis is the open source tool, AWStats.
Before setting up AWStats, you will need to make sure Perl installed on your Windows Server 2003/IIS 6 or Windows Server 2008/IIS 7 machine.

Configuring Web Site Logging

In order to capture the data AWStats tracks, your sites must log the following fields:
  • date
  • time
  • c-ip
  • cs-username
  • cs-method
  • cs-uri-stem
  • sc-status
  • sc-bytes
  • cs-version
  • cs(User-Agent)
  • cs(Referer)

IIS 6 Setup

To configure logging in IIS 6, open IIS Manager and right click on the Web Sites folder and select Properties.
image
On the Web Site tab, click the Properties button in the Enable logging section.
image
In the Logging Properties, configure the schedule to be daily with local time used for file naming and rollover.
image
On the Advanced tab, configure the required fields to be logged.
image
image
Apply your changes.

IIS 7 Setup

To configure logging in IIS 7, open IIS Manager and select Logging from the server configuration options.
image
In the Logging configuration, set up a single log file per site which rolls over daily using the local time for file naming.
image
Click the Select Fields button and check the boxes next to the required fields.
image
Apply your changes.

Setting Up AWStats

Download the AWStats zip package from Sourceforge. Create a folder called ‘awstats’ in your ‘C:inetpubwwwroot’ folder and extract the following files from the downloaded zip file to this folder:
  • /wwwroot/icon
  • /wwwroot/cgi-bin/lang
  • /wwwroot/cgi-bin/lib
  • /wwwroot/cgi-bin/plugins
  • /wwwroot/cgi-bin/awredir.pl
  • /wwwroot/cgi-bin/awstats.model.conf
  • /wwwroot/cgi-bin/awstats.pl
image
Once the files are extracted, copy the “awstats.model.conf” file to a file named “awstats.domain.com.conf” (where domain.com is the site to track), open it in Notepad and configure the options as needed.
The first thing you will need to configure is the log file location, which by default is located here:
  • Server 2003: C:WINDOWSsystem32LogFilesW3SVC[IIS_ID]
  • Server 2008: C:inetpublogsLogFilesW3SVC[IIS_ID]
You can find the IIS ID by looking at the master site listing in IIS Manager and noting the value in the ID column next to the respective site.
image
Set the options in the configuration file. This file has a very good explanation of what each option does, so take a few minutes to review them. Here are a few settings of interest according to the setup above:
  • LogFile=”C:inetpublogsLogFilesW3SVC1u_ex%YY-24%MM-24%DD-24.log” (Server 2008/IIS 7 where the stats are calculated daily)
  • LogFile=”C:WINDOWSsystem32LogFilesW3SVC1ex%YY-4%MM-4%DD-4.log” (Server 2003/IIS 6 where the stats are calculated every 4 hours to be updated throughout the day)
  • LogFormat=”date time cs-method cs-uri-stem cs-username c-ip cs-version cs(User-Agent) cs(Referer) sc-status sc-bytes”
  • SiteDomain=”domain.com”
  • HostAliases=”www.domain.com 11.22.33.44″ (any other URL’s which point to your site)
  • DirIcons=”icon”
  • DefaultFile=”index.php index.html”
Once you have saved your configuration file, run the AWStats Perl Script to compile the stats data. The command looks like this:
C:inetpubwwwrootawstats>C:Perlbinperl.exe awstats.pl -config=domain.com
image
The above command assumes the following (configuration used for this article):
  • The folder “C:inetpubwwwrootawstats” serves the stats through IIS.
  • Perl was installed to the “C:Perl” directory.
  • The config file is named “awstats.domain.com.conf”.
Finally, you can access the stats data through your browser. This URL is publically available for anyone to view unless you configure security via IIS. To test our configuration, just browse to:
http://localhost/awstats/awstats.pl?config=domain.com
image

Scheduling Stats Update

One of the configurations we set in the config file is the ‘LogFile’ location which defines the amount of hours to subtract from the date portions of the file. So to automate the process of compiling your stats, set up a Windows Scheduled Task which runs the command you used above to build the stats on the interval you configured.

Links

Download AWStats (zip package)

Pages