How to get a Windows server to play nicely with WordPress

For my entire career as a designer and developer, I have worked with WordPress almost exclusively. In that time 100% of the web servers I’ve hosted on have been Linux-based, you could say I was spoiled. Recently, I was presented the unforeseen challenge of hosting WordPress on a Windows-based server which was something I’ve never had taken on.

Note: This article assumes you have a basic understanding of installing and moving WordPress. Rather than document each step of the way I’ll outline my own methods. Read for more information about Installing WordPress and moving WordPress.

Installation

The day came where I needed to move a WordPress site on a Linux server to a Windows server. Up until this point, I had installed WordPress more times than I could count, not to mention moving data between databases. WordPress is certainly capable of operating on any server so long as there is support for MySQL and PHP. While it’s more common to host on an Apache driven server that’s not to say it’s the only way to go about it. I’ll link to more hosting options at the end of the article.

Moving files is the same for any server

Moving the files was painless. As with any web server, you can log in via FTP (File Transfer Protocol) and move the files manually. If you want to automate the moving of your files you can also use an auto-deploy service and git to make push files a breeze. Tools like DeployBot or DeployHQ will become your best friend once you maximize the benefits and understand how it all works. I’ll be sure to cover more on this in another article.

Migrating Data

Migrating the data can either be easy as hell or a pain in the ass depending on how you import/export. If you do it via PHPmyAdmin there are a few steps you’ll need to take in order to have a successful migration. The way I’ve always done it is to export the current database’s data as an SQL file.

export-data

Export

Exporting is pretty painless. Log in to your PHPmyAdmin tool and click the Export tab. A new window will display with a lot of checkboxes and options. I admit I have no idea what some of these options mean, but luckily for what we need the default settings should work nicely, well almost…

export-options

This is what displays from with a Windows Server on a GoDaddy hosting plan. I personally don’t use GoDaddy for hosting because it’s a little limiting but sometimes clients don’t know the difference so you have to work with what they give you.

add-drop-table-func

One important option to make sure you check is within the structure settings. The very first checkbox with the label of Add DROP TABLE / VIEW / PROCEDURE / FUNCTION needs to be checked. This option essentially checks if a table already exists and if so overwrites it. If you don’t check this option then your import on the new server will fail.

go

Since the default settings are adequate we can go ahead and click the “Go” button on the bottom right-hand side of the screen. Before clicking Go, you can decide how you want to receive the data on the left-hand side under Save as file. If you check this you can download an actual file. If you uncheck it your screen will redirect and you can copy and paste the SQL data and save it on your own. There’s no real wrong way to do this part.

Import

Import is super straight forward. Just grab the SQL file you downloaded and upload it like you would an image or file. The data gets imported and you should be good to go.

wp-options

In order for WordPress to work (and if your URL changes) you will need to update the siteurl and home option names within the wp_options table.

Isn’t there an easier way?

There totally is. Luckily our friends at Delicious Brains have made a suite of handy WordPress plugins available for easily moving your data between WordPress websites. This plugin is like a dream come true and totally worth the cost if you build a lot of websites. I’m not affiliated with them in any way either, I just really stand behind what they have built. Check out WP Migrate DB Pro to make your WordPress workflow faster than ever before.

Error 500 Internal Server Error and the web.config file

Great, an Error 500. I figured after the above steps WordPress would be up and running and I could go about my day. Unfortunately, after hours of trial and error and multiple database dumps, exports, and imports I took to Google to see what might be a solution to my problem.

What I didn’t realize is that a Windows server doesn’t use a .htaccess file like Linux machines. Having never worked on a Windows server I had never even heard of this.

web.config

Enter the web.config file. It turns out, the web.config file is much like the .htaccess file of the Linux world. The web.config file is an XML document that resides in the root directory of the site or application and contains data about how the web application will act. In other words, it’s pretty much necessary to have to get rid of our nasty error message.

After a little more research I found out what needed to be inside the web.config file. At minimum here’s what worked for me:


<?xml version="1.0" encoding="UTF-8"?>
  <configuration>
    <system.webServer>
      <rewrite>
        <rules>
          <rule name="WordPress Rule" stopProcessing="true">
          <match url=".*" />
            <conditions>
              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
              <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
          <action type="Rewrite" url="index.php" />
         </rule>
        </rules>
       </rewrite>
    </system.webServer>
</configuration>

Be sure to add this code inside a file called web.config within the root directory of your site. Once added your WordPress site should present itself before your eyes! This file can have a lot more configurations. Check out this article to understand how it all works.

Closing Remarks

In the end, of all the aggravation and headaches, I was able to get the site up and running. I thought I was doing everything correctly but as it turns out I missed one small file to make it all work again. Making sure you understand your web server’s environment is pretty crucial to building any website. While some developers are probably already familiar with this practice I can successfully say I learned something new. Sure, it took me an entire day to figure out but you can bet I won’t make that mistake twice.

Migrating Data

web.config Related

WordPress Related

Alternative Hosting for WordPress

  • I’ve also been dealing with a recent move to a Windows server for a client, and it’s been a hell of a time. I’ve messed with the web.config file to no avail, and in getting rather frustrated. The website is up and running for the time being, but the permalinks look like crap. I can’t figure out how to remove /index.php/ from the permalink structure, and some articles suggested it’s not doable. SO. Yay. Lol
    (I am in contact with the current host, so hopefully he can provide some insight, or just fix it….) ????