X

Setting up Websites on Localhost with IIS7

I struggled today to find the ‘best’ way to set up testing websites in IIS7.  Here’s what I ended up doing.

Sort your workspace – these steps were based on my set up with a new Windows 7 machine, Dreamweaver CS5 and IIS7.  I also installed a handy piece of software called Hostsman, which will be useful later.


Step 1.
Set up your site in Dreamweaver.  Select the Servers Option, I made one to the ‘live site’ and then one to my ‘test’ site.

– Server name – Local Testing
– Connect using – Local/Network
– Server folder – anywhere I liked… (more on this later) I put mine under ‘My Documents’, ‘My Web Sites’ – The important this was to make a new folder called ‘example-domain.com’ and then ‘wwwroot’.  (putting the files under ‘wwwroot’ should correspond depending on your website hosting company (some use httppublic for example).
– Web URL – this should be the name you’ll want to use on a browser to view the ‘test’ site.  I followed the format – http://local.example-domain.com (where local is my fake testing sub domain if you like)
– Above click the Advanced ‘tab’ and then select your Server Model (PHP, ASP VBScript etc).

Lastly within Dreamweaver – you can ‘put’ your files to the Test Server.  A quick check on Windows Explorer to see they have all gone into the right place.

———-
Step 2.
There is a file called Hosts.txt – buried in /windows/system32/drivers/etc/  You need to be able to edit this file (notepad will do.  (you might have to change the properties of the file to ensure you have editing rights).

You need to add a single line of code somewhere near where is says – 127.0.0.1 localhost  You line should read:

127.0.0.1 local.example-domain.com

NB – the alternative is to use Hostman Editor, which gives you control over this file and is perhaps friendlier.
———-
Step 3.
Go to IIS7 (Start and type iis into the search box).  Here we will set up a website (as many as we like) that should provide the most realistic test environment we can have.

– Right click ‘Sites’ and select ‘Add web site’.
– Give the site a name like example-domain.com
– Choose a Default Application Pool (there is no need to create one… it may cause additional issues if you do) I choose DefaultAppPool (the others relate to ASP.Net websites).
– Select the Physical Path (My Documents -> My Web Sites… wwwroot)
– Finally below in the Binding section leave everything as is and give the site a Host Name: local.example-domain.com.
———-

And that should be it.  Quick and straightforward to set up as many test websites as you like using Dreamweaver on a Windows 7/IIS7 machine.

To test – within IIS7 on the right column you should see an option to ‘browse web site’ – just click.

What issues did I have.

The main was to do with Root Paths – decent SEO requires you to use Site Root Paths and and NOT relative paths in your website.  for example ‘/’ should lead you back to the home page, images should be referenced ‘/images/photo.jpg’ and not ‘../../images/photo/jpg’.

In the default set up ‘localhost’ is a single website within IIS7 and so when you create sub-folders under ‘inetpub/wwwroot’, all your links break. and if you have written the website properly things like CSS won’t work.

The site has to be a separate and self contained one, this makes even more sense if you’re going to start using databases and applications.

The next big hurdle was accepting that I had to edit ‘Hosts.txt’ every time I wanted to add another website.  It seems an extraordinary additional step to have to take.  This file is randomly buried in Windows and so I was not at all confident about the thinking here, but on research I gave in and did it, (please tell me a better way).

Finally… In IIS when adding a new website you can ‘connect as’ (didn’t use) and ‘test setting…’ When clicking the test settings button I get the following error.

‘The server is configured to use pass-through authentication with a built-in account to access the specified physical path. However, IIS Manager cannot verify whether the built-in account has access. Make sure that the application pool identity has Read access to the physical path. If this server is joined to a domain, and the application pool identity is NetworkService or LocalSystem, verify that $ has Read access to the physical path. Then test these settings again.’

I cannot see how to fix this, so please if anyone finds out please let me know.

Comments

comments

Guy Hoogewerf: