How to Use Internet Information Services (IIS) to Host a Website Locally on Windows

Image Credit: Sulopa solutions Image Credit: Sulopa solutions
<center> Image Credit: Archives.

If you’re creating a website, you’ll probably want to test it before hosting it on the internet to ensure it works properly.

Ideally, you should test your site on the same web server that it will run on when you go live. This allows you to be sure that your site will behave in production the same way it behaves locally. Fortunately, most web servers are easy to install and use on your local computer.

On a Windows PC, you can use Internet Information Services (IIS). IIS comes free with Windows, so all you need to do is enable and configure it to view your website.

What Is Internet Information Services?

IIS is a web server that you can use to host static or dynamic websites. A web server works by serving content—such as HTML, JavaScript, or media files—to a user’s browser, in response to a request.

Some frameworks such as Angular already have basic built-in web servers. These will serve your website to preview and test locally, using the localhost domain. However, there are some scenarios where you need to set up a full-blown web server yourself.

One example of this is when publishing a scene from a Unity project. You are likely to get an error if you try to open the index.html file directly in your browser, without a web server running. In this case, you could store your Unity WebGL files in IIS, and run them on the server.

How to Enable IIS

Enable IIS using the Turn Windows Features On and Off menu on Windows.

  1. Search for Turn Windows Features On and Off using the search bar:

2. Select the Internet Information Services option:

3. Expand Internet Information Services, and select all the sub-features you require:

4. Click OK, and wait for Windows to apply the new changes. In the future, if you decide to remove or change any features, Windows may ask you to restart your computer before applying them.

5. Search for the IIS application, which will now be available to open on your Windows computer:

6. Open IIS to view the IIS console:

How to Create a Simple Test Website

Create a simple static website using HTML and CSS.

  1. Create a new file called index.html. Add the following content to the file:

2. Create a new CSS file called styles.css. Add the following styling to the file.

3. Create a new folder in the C:\inetpub\wwwroot directory on your computer, called MyTestWebsite. This folder is specifically used for storing the web pages and other content that make up your website.

4. Copy or move the index.html and styles.css files into the new MyTestWebsite folder.

How to Add and Configure Your Website Using IIS

To host your website using IIS, create a new website and point it to your content.

  1. In the left-hand sidebar of the IIS console, right-click on the Sites directory.
  2. From the options in the menu, select Add Website, to open the configuration window.
  3. Add a name to the Site name, such as “My Test Website”. IIS will automatically fill in the field for the Application pool.
  4. Add the physical path, which is the location where you have stored your website files on the computer. Click on the three dots to select a folder. From the menu, navigate to the MyTestWebsite folder, under the C:\inetpub\wwwroot directory.
  5. Select https as the Type. The default Port for HTTPS is 443, but you can change the port to something else if that’s currently in use.
  6. You can also configure a host name, but leave this blank for now.
  7. For the SSL Certificate, select IIS Express Development Certificate.
  8. Select Start Website immediately, and click on OK.
  9. Highlight the new My Test Website directory in the left-hand column.
  10. Click on Advanced Settings, which is in the list of options on the right side of the panel.
  11. Under the Behavior section, change the Enabled Protocols option to “https”, and click on OK.
  12. If you want to edit these details at any point in time, you can click on the Basic Settings or Advanced Settings options in the right-hand menu.

How to Stop, Start or Restart Your Website on the Web Server

To start your web server and view your website, click on the Browse option in the right-hand menu. You can also restart or stop the web server at any time.

  • To run your web server, click on Browse *:443 (https) in the right-hand menu.
  • Your website should now be running on the web server. You can access it via the URL https://localhost/. If you receive a warning about your site connection not being secure, you may have to use a different valid SSL certificate. You can find good documentation from Microsoft on how you can create a new SSL Certificate and use it in IIS.
  • To stop or restart the web server, click on Stop or Restart on the right-hand menu.

Hosting a Website Using IIS

Local testing is an important part of any development cycle, including when you’re building a website.

You can host your website locally using the Internet Information Services (IIS) web server. You can use it to host any static website (such as a standard HTML or CSS site) or dynamic website (such as an ASP.NET site).

There are various options you can choose from when hosting your website online. If you are hosting a simple website, you could store your website files on Dropbox, Google Drive, or One Drive, before hosting them.

ALSO READ: Learn Web Development as an Absolute Beginner