SETTING UP A WORDPRESS DEVELOPMENT ENVIRONMENT ON WINDOWS WITH IIS
In order to develop a WordPress site on your own development machine, you’ll need to setup a local web server and run WordPress on that. Why not use the Internet Information Services server, which comes with your Windows installation? This guide explains how to setup IIS, PHP, MySQL and WordPress hassle-free.
Already have WordPress running on your development machine?
Start building WordPress theme files, styles, header and footer
Step 1. Setting up your computer as a web server
In order to do web development, you’ll need your computer to act as your own local web server. This means installing software on it that can serve websites through your browser – for you alone. When your site and theme are all done, you can upload them to a remote web server, but you’ll want to do all development on your own computer. Your development cycle will be much faster that way, since uploading every little change to a server through FTP will make you tear your hair out.
For basic websites that consist only of HTML files, you can just point your browser to a file on your computer and have it render the file. WordPress websites on the other hand, like most other content management systems, require PHP, and PHP requires a web server to run.
There are various pieces of software that can act as web servers. Many people use Apache, which will run of many operating systems and is very powerful. For this guide, we’ll assume that you use a Windows machine and will use the Windows-only Internet Information Services (IIS), which is already included in your Windows installation and easy to set up.
All that is necessary to install Internet Information Services is activating it. To do so, find the “Windows Features” area of the Control Panel in Windows. It’s easy to find by just typing
Features in the Start menu and selecting Turn Windows features on or off. You’ll be presented with a list of features; find World Wide Web Services and activate the checkboxes as below (this should be the default situation when you simply check World Wide Web Services):
IIS will now be installed.
Let’s test that it works. Create a directory somewhere on your hard drive for your test website. Now start the IIS manager by running Internet Information Services (IIS) Manager (you can find it by typing
inetmgr in your Start menu). In the control panel that appears, expand the tree on the left to find Sites. Right-click that and select Add Website:
A window pops up inviting you to enter your new site details. Assuming you created the folder
your-directory, fill it out like this (remember, your-directory is whatever name you choose for your website. Keep it short and don’t uses spaces or special characters):
IIS is now serving a new website from your new directory, and it’s in this directory that we’ll eventually install WordPress and build our site. However, if you visit http://your-directory in your browser now, it will try to access the internet and not your local server. You’ll first need to configure Windows to understand that this particular URL must point to your local web server, or your requests will never reach your local IIS.
To do so, start Notepad (or whatever text editor you prefer to use) in Administrator mode (find it in the Start menu, right-click it and select “Run As Administrator”). You will need to open a Windows file that requires Administrator privileges to edit. In Notepad, open C:\Windows\System32\drivers\etc\hosts. This file contains special instructions that Windows will use to look for sites, and it is here that we will tell Windows that your-directory is actually a website on the local computer.
At the bottom of the hosts file, add a new line with the following text:
The IP-address “127.0.0.1” is a special address known as the local loopback. It simply refers to your own computer, which is exactly what we need in our scenario.
Save the file (you’ll need Administrator privileges) and close it.
From now on, whenever you visit http://your-directory in your browser, it will talk to your local IIS service and not try to find the URL your-directory on the internet.
It’s important to test that all is well. Create a new file “test.html” in your site’s directory and put some test content in it (“hello world” is traditional). Open http://your-directory/test.html in your browser. If “hello world” appears, all is working as it should.
Step 2. Installing PHP
Installing PHP on IIS is easy thanks to a little tool released by Microsoft called the Web Platform Installer. Download and install it. On launch, it will query Microsoft’s servers looking for products that can be installed, which may take a while. When it shows you the list of available products, select “PHP 7.1.7” (x86 or x64 depending on your machine) and have the tool install it.
(It should be possible to use the Web Platform installer to install IIS as well – I’ve not tried that, but that might be even easier than the steps described above. The instructions that I gave are what works for me; YMMV).
PHP should now be available with all the bells and whistles that come with it, such as interfaces to the MySQL database (which we’ll need for WordPress), image manipulation plugins etc. It should all be there without needing further configuration from you.
Let’s verify that everything works. Create a new file called
test.php in your site’s directory and place the following content in it:
Now point your browser to http://your-directory/test.php. If you see a bunch of information about PHP, everything is fine. If you get a blank screen, the literal text
phpinfo(); or the file is offered for download then PHP is not yet working and IIS is serving the PHP file like any other file, without any PHP processing. If this is the case, go back to inetmgr and find your site under Sites. Select it, and then select the option Handler Mappings in the center panel. There should be a mapping for PHP there. If there isn’t one, create one with the following settings:
If everything works – congratulations! You’ve got a local webserver with PHP installed.
Step 3. Installing MySQL
Most of what we need for WordPress is now in place, but we still need a database. WordPress uses a database to store everything about your website: posts, pages, users and settings. The database system used by WordPress is MySQL and you’ll need to install this on your local machine.
MySQL is available to install through the Web Platform Installer. I’ve not done that, but I did notice that the MySQL version on offer tends to be a little behind the times. I therefore recommend that you begin by downloading the latest version of MySQL. This will take you straight to the download page for the free MySQL Community Server. You can use either the web-based (partial download) or the community installer (full download).
During the installation, you will be asked to pick a root password. This is the master password for all your databases, so keep it somewhere safe.
At some point, the installer will ask whether you want to install MySQL as a Windows Service. You’ll want to do this, because this’ll make sure that MySQL starts up whenever your computer starts up with no further intervention from you. It’ll always be available.
This will open the MySQL console. We’ll create a database for our new WordPress website now. Do so by typing:
(For “mydatabase”, pick any database name you like.)
In this tutorial, WordPress will access this database as the “root” user. In a testing environment, such as your local machine, this is fine, but you should never do this on a production server. In a production environment, you must create a specific user for the WordPress database.
Congratulations again, you’ve got MySQL running, and with that, the last requirement for running WordPress.
Step 4. Installing WordPress
It is now time to install WordPress itself. Download the latest version of WordPress. You will receive a .zip file. Unpack the contents of the wordpress folder in the zip to this directory.
Visit the url http://your-directory in your browser. This should now show you the WordPress installation screen.
Fill out your database information.
For now, you can use “root” as the database user. When you move your site to a production server, you must change this! At a later stage, you can always edit the
wp-config.phpfile to change the database credentials.
WordPress will now write initial data to the MySQL database. When it’s done, you can enter WordPress’s administration panel.
This post was written with a specific purpose in mind. Next time, we’ll look at how to build a WordPress theme from the ground up: