URL Rewriting Using Database and IHttpModule in IIS7/8

Step-1: In database table keep a field named “ProfilePageTitle” for rewrite URL

SELECT [SystemId]
,[UserId]
,[RoleId]
,[UserName]
,[ProfilePageTitle]
,[UserPicture]
,[Designation]
,[Email]
,[LoginId]
,[Password]
,[PasswordHints]
,[HeadStatus]
,[OnLeave]
,[DisplayOrder]
,[ErrorCounter]
FROM tblUserSetup

Step-2: In your project add “IHttpModule” i.e. FixURLs.cs

public class FixURLs : IHttpModule

Step-3: add code to FixURLs.cs

#region IHttpModule Members
public void Dispose()
{
// do nothing
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
#endregion

void context_BeginRequest(object sender, EventArgs e)
{
String qs = ” SELECT UserId, ProfilePageTitle FROM tblUserSetup WHERE UserId <> ‘A786’ “;
DataTable dt = new DataTable();
try
{
dt = ClsCommon.GetAdhocResult(qs).Tables[0];
}
catch (Exception ex) { }
HttpApplication app = (HttpApplication)sender;
for (Int32 i = 0; i < dt.Rows.Count; i++)
{
if (app.Request.RawUrl.ToLower().Contains(“/” + dt.Rows[i][“ProfilePageTitle”].ToString()))
{
app.Context.RewritePath(“~/frmFacultyInfoDetails.aspx”, “”, “qs=faculty,info,” + dt.Rows[i][“UserId”].ToString());
}
}
}

Step-4: .aspx and .aspx.cs code:

<asp:GridView ID="grvFacultyList" Width="650px" runat="server" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" Font-Size="14px"
Font-Underline="False" AutoGenerateColumns="False" ShowHeader="False" ForeColor="Black"
GridLines="Horizontal" OnRowDataBound="grvFacultyList_DataBound">
<Columns>
<asp:TemplateField HeaderText="">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblDesignation" runat="server" Text='<% #Eval("Designation") %>' Visible="false" />
(<%#Container.DataItemIndex+1 %>)
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemStyle HorizontalAlign="Left" />
<ItemTemplate>
<%--<asp:HyperLink ID="hlUserName" runat="server" Text='<% #Eval("UserName") %>' target="_blank"></asp:HyperLink>--%>
<asp:HyperLink ID="hlUserName" runat="server" Text='<% #Eval("UserName") %>' target="_blank"></asp:HyperLink>
<asp:Label ID="lblUserName" runat="server" Text='<% #Eval("UserName") %>' Visible="false" />
<br />
<asp:Label ID="lblEmail" runat="server" Text='<% #Eval("Email") %>' />
<br />
<asp:HyperLink ID="hlPersonalHomePage" runat="server" NavigateUrl='<% #Eval("Url") %>'
Text='<% #Eval("Url") %>' target="_blank" Visible="true"></asp:HyperLink>
<%--<asp:LinkButton ID="lbUrl" runat="server" Text='<% #Eval("Url") %>'></asp:LinkButton>--%>
<asp:Label ID="lblUrl" runat="server" Text='<% #Eval("Url") %>' Visible="false" />
<asp:Label ID="lblUserId" runat="server" Text='<% #Eval("UserId") %>' Visible="false" />
<asp:Label ID="lblProfilePageTitle" runat="server" Text='<% #Eval("ProfilePageTitle") %>' Visible="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Image ID="ImageUserId" Width="80px" Height="100px" runat="server" ImageUrl='<%#"HandlerFacultyImage.ashx?qsId=" + Eval("Id") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="Black" HorizontalAlign="Right" BackColor="White" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#4B4B4B" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#242121" />
</asp:GridView>

protected void grvFacultyList_DataBound(object sender, GridViewRowEventArgs e)
{
foreach (GridViewRow gvr in grvFacultyList.Rows)
{
HyperLink hlUserName = gvr.FindControl(“hlUserName”) as HyperLink;
Label lblUserName = gvr.FindControl(“lblUserName”) as Label;
Label lblUserId = gvr.FindControl(“lblUserId”) as Label;

Label lblProfilePageTitle = gvr.FindControl(“lblProfilePageTitle”) as Label;

HyperLink hlPersonalHomePage = gvr.FindControl(“hlPersonalHomePage”) as HyperLink;
hlUserName.NavigateUrl = “~/” + lblProfilePageTitle.Text.ToString().Trim();
}
}

Step-5: IIS setup and Module adding:

i. Open Internet Information Service (IIS) Manager
ii. Select application and click the tab “features view”
iii. Modules–> add managed modules… –> in Type: field select the Module “FixUrls” Local Module.
Step-6: web.config
<configuration>
<system.web>
<httpModules>
<add name="FixURLs" type="cse.FixURLs, cse" />
</httpModules>
<system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="cse.FixURL" type="cse.FixURLs" preCondition="managedHandler" />
<add name="FixUrl" type="FixURLs" preCondition="managedHandler" />
</modules>
</system.webServer>
<configuration>

Directory Browse

http://www.iis.net/configreference/system.webserver/directorybrowse

Overview

The <directoryBrowse> element controls the information that is displayed in a directory listing when you enable directory browsing for your Web site or application.

The <directoryBrowse> element can contain two attributes. The enabled attribute determines whether directory browsing is enabled for the site, application, or directory. The showFlags attribute defines the information about each file in the directory that Internet Information Services (IIS) will display. IIS can display the last modified date and time, the long date for the last modified date, the file size, and the file name extension. You can choose which of these, if any, IIS will display.

Compatibility

Version Notes
IIS 8.5 The <directoryBrowse> element was not modified in IIS 8.5.
IIS 8.0 The <directoryBrowse> element was not modified in IIS 8.0.
IIS 7.5 The <directoryBrowse> element was not modified in IIS 7.5.
IIS 7.0 The <directoryBrowse> element was introduced in IIS 7.0.
IIS 6.0 The <directoryBrowse> element replaces the IIS 6.0 DirBrowseFlags metabase property.

Setup

The <directoryBrowse> element is included in the default installation of IIS 7 and later.

If directory browsing has been uninstalled, you can reinstall it using the following steps.

Windows Server 2012 or Windows Server 2012 R2

  1. On the taskbar, click Server Manager.
  2. In Server Manager, click the Manage menu, and then click Add Roles and Features.
  3. In the Add Roles and Features wizard, click Next. Select the installation type and click Next. Select the destination server and click Next.
  4. On the Server Roles page, expand Web Server (IIS), expand Web Server, expand Common HTTP Features, and then select Directory Browsing. Click Next.
    .
  5. On the Select features page, click Next.
  6. On the Confirm installation selections page, click Install.
  7. On the Results page, click Close.

Windows 8 or Windows 8.1

  1. On the Start screen, move the pointer all the way to the lower left corner, right-click the Start button, and then click Control Panel.
  2. In Control Panel, click Programs and Features, and then click Turn Windows features on or off.
  3. Expand Internet Information Services, expand World Wide Web Services, expand Common HTTP Features, and then select Directory Browsing.
  4. Click OK.
  5. Click Close.

Windows Server 2008 or Windows Server 2008 R2

  1. On the taskbar, click Start, point to Administrative Tools, and then click Server Manager.
  2. In the Server Manager hierarchy pane, expand Roles, and then click Web Server (IIS).
  3. In the Web Server (IIS) pane, scroll to the Role Services section, and then click Add Role Services.
  4. On the Select Role Services page of the Add Role Services Wizard, select Directory Browsing, and then click Next.
  5. On the Confirm Installation Selections page, click Install.
  6. On the Results page, click Close.

Windows Vista or Windows 7

  1. On the taskbar, click Start, and then click Control Panel.
  2. In Control Panel, click Programs and Features, and then click Turn Windows Features on or off.
  3. Expand Internet Information Services, expand World Wide Web Services, then expand Common Http Features.
  4. Select Directory Browsing, and then click OK.

How To

How to enable directory browsing

  1. Open Internet Information Services (IIS) Manager:
    • If you are using Windows Server 2012 or Windows Server 2012 R2:
      • On the taskbar, click Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows 8 or Windows 8.1:
      • Hold down the Windows key, press the letter X, and then click Control Panel.
      • Click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
    • If you are using Windows Server 2008 or Windows Server 2008 R2:
      • On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows Vista or Windows 7:
      • On the taskbar, click Start, and then click Control Panel.
      • Double-click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
  2. In the Connections pane, expand the server name, and then go to the site, application, or directory where you want to enable directory browsing.
  3. In the Home pane, double-click Directory Browsing.
  4. In the Actions pane, click Enable.
  5. In the Directory Browsing pane, select the options that correspond to the information you want to display for each item in the directory, and then click Apply.

Configuration

The <directoryBrowse> element is configurable at the site level, application level, or directory level in the appropriate Web.config file.

Attributes

Attribute Description
enabled Optional Boolean attribute.

Specifies whether directory browsing is enabled (true) or disabled (false) on the Web server.

The default value is false.

showFlags Optional flags attribute.

The showFlags attribute can have one or more of the following possible values. If you specify more than one value, separate the values with a comma (,). The default values are Date, Time, Size, Extension.

Value Description
Date Includes the last modified date for a file or directory in a directory listing.
Extension Includes a file name extension for a file in a directory listing.
LongDate Includes the last modified date in extended format for a file in a directory listing.
None Specifies that only the file or directory names are returned in a directory listing.
Size Includes the file size for a file in a directory listing.
Time Includes the last modified time for a file or directory in a directory listing.

Child Elements

None.

Configuration Sample

The following example enables directory browsing and uses the showFlags property to configure IIS to display the date and time modified for each item in the directory, along with each item’s file size and file name extension.

<configuration>
   <system.webServer>
      <directoryBrowse enabled="true" showFlags="Date,Time,Extension,Size" />
   </system.webServer>
</configuration>

Sample Code

The following examples enable directory browsing for a site named Contoso and use the showFlags property to configure IIS to display the date and time modified for each item in the directory, along with each item’s file size and file name extension.

AppCmd.exe

appcmd.exe set config "Contoso" -section:system.webServer/directoryBrowse /enabled:"True" /showFlags:"Date, Time, Size, Extension"

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample {
   private static void Main() {
      using(ServerManager serverManager = new ServerManager()) { 
         Configuration config = serverManager.GetWebConfiguration("Contoso");

         ConfigurationSection directoryBrowseSection = config.GetSection("system.webServer/directoryBrowse");
         directoryBrowseSection["enabled"] = true;
         directoryBrowseSection["showFlags"] = @"Date, Time, Size, Extension";

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample
   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetWebConfiguration("Contoso")
      Dim directoryBrowseSection As ConfigurationSection = config.GetSection("system.webServer/directoryBrowse")
      directoryBrowseSection("enabled") = True
      directoryBrowseSection("showFlags") = "Date, Time, Size, Extension"
      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Contoso";

var directoryBrowseSection = adminManager.GetAdminSection("system.webServer/directoryBrowse",
   "MACHINE/WEBROOT/APPHOST/Contoso");
directoryBrowseSection.Properties.Item("enabled").Value = true;
directoryBrowseSection.Properties.Item("showFlags").Value = "Date, Time, Size, Extension";

adminManager.CommitChanges();

VBScript

Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Contoso"

Set directoryBrowseSection = adminManager.GetAdminSection("system.webServer/directoryBrowse", "MACHINE/WEBROOT/APPHOST/Contoso")
directoryBrowseSection.Properties.Item("enabled").Value = True
directoryBrowseSection.Properties.Item("showFlags").Value = "Date, Time, Size, Extension"

adminManager.CommitChanges()

Install WordPress with IIS 7, PHP, MySQL – the easy way

Recently I’ve started to play around with WordPress.com however the best way to get the most out of all WordPress extras is to install it on your own PC. In this tutorial we will go through the steps to install IIS 7, PHP  5, MySQL 5 and WordPress 3.

Step 1: Files to Download

  1. PHP 5.3 – windows installer non-thread safe.
  2. MySQL 5.5 – grab the MSI installer for either 32 or 64 bit machine. Also grab this GUI Workbench tool.
  3. WordPress

Step 2: Install IIS 7

Go to Start -> Control Panel -> Programs -> Turn Windows Feature On/Off.

Expand the Internet Information Services tick:

  • Web Management Tools/IIS Management Console
  • World Wide Web Services/Application Development Features/CGI
  • World Wide Web Services/Common HTTP Features/Default Document, Directory Browsing, HTTP Errors, Static Content.

Click “Ok” and wait for it to finish!

In your browser go to http://localhost and if installed correctly the main screen of IIS7 should appear.

Step 3: Install PHP

Run the installer and go with the defaults. Select “IIS FastCGI” when prompted. The installer will automatically add pre-sets to IIS. Done!

Test the PHP install by creating a text file in C:\inetpub\wwwroot\test.php. Name it “test.php” and put the following code in

<?php
 phpinfo();
?>

Now go to http://localhost/test.php and you should see the PHP screen.

Step 4: Install MySQL

Run the installer for MySQL 5.5 and the GUI Management Tool. Choose “Typical” setup when prompted and use the default settings.

Once completed an “Instance Configuration Wizard” will start. Follow the default settings. Enter the root password when prompted, keep it simple and write it down. Let the wizard run through.

Next install the GUI Workbench. Again follow through with the default settings.

Step 5: Create wordpress database

Open the GUI Workbench through Start->All Programs -> MySQL -> MySQL Workbench

In the SQL Development column double click on “Local instance MySQL”. Once logged in, on the left-hand menu you will see “Add Schema”, click it. Change the “new_schema” name to “wordpress”. Finish by clicking “Apply” and “Finish”. Now next to “test”, you should see “wordpress”.

Step 6: Install WordPress

Unzip the downloaded wordpress.zip folder. Copy the contents into C:\inetpub\wwwroot\wordpress.

To start the installer in you browser go to http://localhost/wordpress/

When prompted put in the database name, and root passwords we had in step 4 & 5

Once completed go to http://localhost/wordpress/wp-login.php to start creating your first WordPress site.

Extra Step: Turn automatic on for IIS and MySQL services

Most likely you won’t be playing around with WordPress everyday, so it makes sense to only turn on the servers when you need to. MySQL and IIS are set to turn on automatically when the PC starts.

To turn off the automatic start, go to Control Panel -> System and Security -> Administrative Tools -> Services

Scroll down to “MySQL”, right-click to “Properties” and set “Startup Type”: to Manual

Do the same for “World Wide Web Publishing Service”.

Common Problems:

WordPress could not create wp-config.php. Go into C:\inetpub\wwwroot\wordpress copy the wp-config-sample.php and change the DB_NAME, DB_USER, DB_PASSWORD, DB_HOST values. and save it as wp-config.php

WordPress can’t upload any files, go to C:\inetpub\wwwroot\wordpress\wp-content right-click to select Properties -> Security -> Edit. Give IIS_IUSRS “Full Control”

When I go http://localhost/wordpress/ a list of files show. Open up the IIS Manager. Select Sites-> Default Web Site -> wordpress , double-click on “Default Document” in the Features View. Add “index.php”

If you liked this tutorial or spotted any errors please let me know by leaving a comment below.

Install Internet Information Services 7.0 and WordPress 3.0.3 by Using the Microsoft Web Platform Installer 3.0

This article describes how to install and configure WordPress 3.0.3 on Windows Server 2008 R2 by using the Microsoft Web Platform Installer (Web PI) version 3.0.

The Web PI is a free tool that makes getting the latest components of the Microsoft Web Platform—including Internet Information Services (IIS), MySQL, the Microsoft .NET Framework, and Visual Web Developer—quick and easy. The Web PI also lets you install web applications such as WordPress with the built-in Windows Web App Gallery.

To install WordPress on IIS 7.0 by using the Web PI 3.0, follow these steps:

Prequisites

Step 1. Install the Web Platform Installer 3.0

Step 2. Select the products and applications to install

Step 3. Review and configure the selected products and applications

Step 4. Complete the installation and configuration

Step 5. Enable clean URLs (Pretty Permalinks)

Prerequisites

The supported operating systems for the Web PI 3.0 are Windows 7, Windows Vista Service Pack 1 (SP1), Windows Vista, Windows XP Service Pack 2 (SP2) and later versions, Windows Server 2008 R2, Windows Server 2008, and Windows Server 2003 Service Pack 1 (SP1) and later versions.

For this guide, it is assumed that you have Windows Server 2008 R2 installed on your computer. You will also need an Internet connection and administrator privileges for your computer.

It is a good idea to confirm that your system meets the hardware requirements for IIS 7.0. See http://technet.microsoft.com/en-us/library/cc268240.aspx for more information.

Step 1. Install the Web Platform Installer 3.0

In this step, you begin to install the Web PI 3.0, which is a 1.3 MB download.

  1. Log on to Windows Server 2008 R2 as a user who has administrative privileges.
  2. Start Windows Internet Explorer.
  3. Go to http://www.microsoft.com/web/downloads/platform.aspx, and then click Download It Now.
    Microsoft Web Platform Installer 3.0 webpage
  4. Click Run.
    File download security warning
  5. Click Run again.
    Internet Explorer security warning
  6. Wait a few seconds for the Web PI 3.0 to start.

Step 2. Select the products and applications to install

In this step, you select the version of WordPress that you want to install. WordPress 3.0.3 is used in this guide.

  1. Next to WordPress, click Add.
    Note: If WordPress is not in the items list, click Applications in the left navigation pane.
    Application selection
  2. Click Install.
    Application selection (continued)

Step 3. Review and configure the selected products and applications

In this step, you review and configure what you have added. Additionally, you add the database, name the MySQL database, and name the WordPress 3.0.3 site.

  1. When you are asked which type of database you want to use, leave MySQL selected.
    Note: This will install MySQL 5.1 for Windows to handle all the database transactions that are required by WordPress.
  2. In the list, select Install it on my machine, and then click Continue.
    Database engine selection
  3. Scroll down to confirm that all the following items have been automatically included as dependencies:
    • IIS 7.0
    • PHP 5.3.5
    • IIS URL Rewrite 2.0
    • Windows Cache Extension 1.1 for PHP 5.3
    • MySQL 5.1 for Windows
      Note: Windows Cache Extension is used to increase the speed of PHP applications that are running on your web host. IIS URL Rewrite allows “Pretty Permalinks” to be enabled for WordPress.
  4. Review the files to be downloaded and installed, as well as the license agreements, and then click I Accept.
    Application installation summary
  5. Specify a password for the MySQL administrator user name (root), and then click Continue.
    Note: It is important to remember this password because you will be asked for this password in the steps that follow.
    MySQL root password setup
  6. Allow the Web PI installation to complete.
  7. In the Web Site box, leave Default Web Site selected.
  8. In the ‘WordPress’ application name box, type a name for the WordPress 3.0.3 site, and then click Continue. For example, type myWordPress.
    Site information
  9. Leave Create new database selected.
  10. Type the database administrator user name (root) and password.
    Note: This account is used to create and manage the database that is needed for WordPress.
    Application configuration
  11. Type the database user name.
    Note WordPress will use this account to access and write to the database as needed.
  12. Type the password for the database user name.
  13. Leave the default database server name, localhost.
    Application configuration (continued)
  14. You may customize the name of the WordPress database as desired.
  15. Use the WordPress key generator at http://api.wordpress.org/secret-key/1.1/ to generate four unique keys, and then copy the keys into the following fields:
    • Unique Key for Passwords
    • Unique Key for Secure Passwords
    • Unique Key for Authentication
    • Second Unique Key for Authentication
      Note: You will not be required to recall these keys later.
  16. Click Continue.
    Application configuration (continued)
  17. Click Finish.
    Installation completed
  18. Click Exit to close the Web PI 3.0.

Step 4. Complete the installation and configuration

In this step, you complete the installation.

  1. Switch to Internet Explorer.
  2. Go to your WordPress website. For example, go to http://localhost/myWordPress.
  3. In the Site Title box, type the name of your site.
  4. In the Password, twice boxes, type a password for the admin account.
    WordPress site configuration
  5. In the Your E-mail box, type the email address for the admin account.
  6. Click Install WordPress.
    WordPress site configuration (continued)
  7. Click Log In.
    WordPress site configuration completed
  8. Type admin, type the password, and then click Log In.
    WordPress login

Step 5. Enable clean URLs (Pretty Permalinks)

In this step, you enable Pretty Permalinks now that WordPress has been installed.

  1. In the Dashboard menu, click Settings.
    WordPress dashboard menu
  2. Scroll down, and then click Permalinks.
    Settings
  3. Under Common settings, select a common Permalink setting or select Custom Structure to create your own Permalink, and then click Save Changes.
    Permalink settings
  4. Click in the gray text field, press CTRL + A, and then press CTRL + C.
    Web.config file contents
  5. Start Notepad as an administrator. To do this, click Start, type notepad in the search box, right-click Notepad in the list of results, and then click Run as administrator.
    Start menu
    Run as administrator command
  6. If you are prompted by User Account Control, click Yes.
    Administrative allowance
  7. In Notepad, press CTRL + V to paste the code that you copied from the WordPress configuration page.
    Web.config file contents
  8. Click File, and then click Save As.
    Notepad Save As menu
  9. In the Save As dialog box, browse to C:\intepub\wwwroot\myWordPress.
    Note: This step assumes that you named the WordPress site myWordPress during installation. If you used a different name, use that name instead of myWordPress.
  10. In the File name box, type web.config.
  11. In the Save as type box, click All Files.
  12. Click Save, and then close Notepad.
    Save As dialog box

The installation is now complete, and you are ready to use WordPress!

Install and Configure PHP on your IIS 7.5 server

http://www.iisunderground.com/installing-php-on-iis/

http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

Installing PHP

PHP LogoThis tutorial will guide you through setting up PHP on your IIS 7.5 server.

Time to complete: ~15 minutes

Requirements: Working installation of IIS 7.5.

 

1. Download PHP

You can get the PHP binaries from http://windows.php.net/download/.

You will need the VC9 x86 non thread safe version in the ZIP format.

 

2. Unpack PHP

Once you have downloaded PHP, un-zip the package to a location of your choice.

The recommended location is c:\php5\ but in this installation example we’ll be using d:\php5\.

 

3. Install the C++ Runtime

PHP is compiled using the Visual Studio Compiler so we must install the C++ Runtime in order for PHP to work.

If you do not do this step, you will get an Error 500 from the fast-cgi module and PHP will not work.

– Browse to http://windows.php.net/.

– On the left side, select the download link for Microsoft 2008 C++ Runtime (x86) (link working at time of posting).

– Run the installer and follow the on screen instructions..

 

4. Install the CGI module in IIS

The CGI module is necessary for PHP to run. By default this isn’t installed so we will need to do this before we can proceed.

Depending on the version of Windows you are running the procedure is slightly different, so you will need to choose from one of the two methods below.

 

Windows Server 2008 and 2008 R2

Navigate to Start\Control Panel\All Control Panel Items\Administrative Tools and open Server Manager.

– In the left hand side there is a tree of services, navigate to Roles > Web Server (IIS).

– Scroll down until you see Role Services.

– Select Add Role Services.

– Find Application Delevopment and then CGI and select the tickbox.

CGI role for IIS in Windows Server 2008

– Click Next and then Install

– When it has finished, you may need to restart IIS or the computer. Do this if requested.

 

Windows Vista/7

– Navigate to Start\Control Panel and open Programs and Features.

– On the left select Turn Windows features on or off.

– In the tree of services, navigate to Internet Information Services\World Wide Web Services\Application Development Features and then select CGI.

CGI role for IIS in Windows7/Vista

– Click OK to start the installation.

– When it has finished, you may need to restart IIS or the computer. Do this if requested.

 

5. Installing PHP

We that we have the necessary roles we can now install PHP.

 

– Load up the IIS Manager by going to Control Panel\All Control Panel Items\Administrative Tools and opening Internet Information Services (IIS) Manager.

– In the folder tree on the left select your server, then select the site you want to add PHP to.

– In the icon view, select Handler Mappings.

– On the right, select Add Module Mapping.

– Fill out the fields as below:

 

Request Path: *.php

Module: FastCgiModule

Executable: d:\php5\php-cgi.exe     Remember to enter the path you un-zipped PHP to.

Name: php5     You can select any name you wish.

 

– Now click the button Request Restrictions…

– On the Mapping Tab click the check box and then select File.

Default Index File / Default Document

– Click OK twice and the module is now installed.

 

6. Adding an index file/default document for PHP

An index file/default document is the file that is first called automatically when you visit a folder. For example visiting http://www.iisunderground.com will automatically invoke index.php from the root folder. We need to tell IIS what we want to use as this file.

 

– On the left of the IIS Manager, select the site we are working on again to return to the page of icons.

– From here select Default Document.

– On the right click Add.

– In the box, enter index.php

– Click OK and the index file/default document is now added.

 

You can feel free to add more here later if you want to use something other than index.php as your default file.

 

7. Testing our installation

To make sure the install has worked, we need to create a test PHP file.

– Create a new file in the folder you have stored your websites files in.

– Name it test.php

– Inside it, put the following code:

 

<?php phpinfo(); ?>

 

– Save it and then visit the URL to test.php and you should get something like this:

An example of a PHPInfo page

If you see something similar to that then congratulations, PHP is working! If not, go back and follow each step again to see where you went wrong. If you still have problems, drop us a line on our Facebook page.

 

Now you need go and learn about configuring your php.ini file to secure your server from malicious attacks on your scripts.

 

Finished.

 

Microsoft Says:

 

Install and Configure PHP

By Tali Smith

November 15, 2009

Introduction

The fastest and easiest way to install PHP on Internet Information Services (IIS) is by using the Microsoft® Web Platform Installer (Web PI). Web PI completely automates setting up IIS, FastCGI, and the latest version of PHP from the php.net Web site. With Web PI, you can navigate to the “Web Platform” tab and select “PHP” under “Framework and Runtimes” customize link. Alternately, use the instructions that follow as guidance for installing PHP with Windows® Installer or using a compressed (Zip) file installation.

There are two builds for each PHP version: one is thread-safe, and one is not (referred to as the non-thread-safe [NTS] version). The thread-safe version is designed for environments where the Web server core can keep the PHP engine in memory, running multiple treads of execution for different Web requests simultaneously. The architecture of IIS and the FastCGI extension provide an isolation model that keeps requests separate, removing the need for a thread-safe version. The NTS version does not have any of the code that allows PHP to manage multiple threads. As a result, there is a performance improvement on IIS when using the NTS version when compared to the tread-safe version because the NTS version avoids unnecessary thread-safety checks (FastCGI ensures a single-threaded execution environment).

Install PHP

There are two main ways to install PHP on a Windows®-based computer: download the Windows Installer or use the Windows Zip file from the PHP Web site. Either method will get PHP working, but both have some extra steps that are needed to make PHP work well.

Windows Installer
The Windows Installer version can get a complete PHP environment up and running, but the installation of extensions can be confusing. By default, no extensions are installed, and this can adversely affect the usefulness of the PHP installation. Alternately, all of the extensions can be installed; this results in an unstable system because some of the extensions can conflict with others. It is generally easier to use the Zip file installation.

Zip File Installation
To use the Zip file installation, follow the instructions in Using FastCGI to Host PHP Applications on IIS 7.0 and Above. The Zip file installation installs many of the extensions that are available for the Windows Installer version; however, none of the extensions are enabled until their entries in the Php.ini file are set up.

1. Download the latest non-thread-safe Zip file package with binaries of PHP. Under Windows Binaries, click on the most current PHP non-thread-safe Zip package to download the PHP files.

2. Unpack the files to a directory of your choice (for example, C:\PHP) on your IIS server.

3. Rename the Php.ini-recommended to php.ini.

4. Open the Php.ini file in a text editor, then uncomment and modify settings as follows:

a. Set fastcgi.impersonate = 1.
FastCGI under IIS supports the ability to impersonate security tokens of the calling client. This allows IIS to define the security context that the request runs under.

b. Set cgi.fix_pathinfo=0
The cgi.fix_pathinfo provides PATH_INFO/PATH_TRANSLATED support for Common Gateway Interface (CGI). Setting this to 1 will cause PHP CGI to fix its paths to conform to the specification.

c. Set cgi.force_redirect = 0.

d. Set open_basedir to point to a folder or network path where the content of the Web site(s) is located.

e. Set extension_dir to point to a location where PHP extensions reside. For PHP 5.2.X, this is typically extension_dir = “./ext” .

f. Set error_log=”C:php_errors.log”
This can help with troubleshooting.

g. Enable the required PHP extension by un-commenting corresponding lines. More information follows in the section, Extensions.

Figure 1 Windows extensions

5. Click on Start, Settings, Control Panel, and then double-click on the System icon (using the class view).

6. Click on the Advanced system settings link in the left column.

7. From the System Properties window, click on the Advanced tab, and then click on the Environment Variables button at the bottom.

8. Select the Path variable from the System Variables section, and then click on Edit. Add: c:\php to your system path.

Figure 2: Edit System Variable

9. Click OK until you have exited the System Properties window.

10. Start IIS Manager by clicking on Start, Programs, Administrative Tools, and then Internet Information Services (IIS) Manager.

11. From the IIS Manager, click on the hostname of your server in the Connections panel on the left.

12. Double-click on the Handler Mappings icon.

Figure 3: Internet Information Services (IIS) Manager

13. From the Handler Mappings Actions panel, click on Add Module Mapping.

Figure 4: Handler Mappings

14. Type the following information into the appropriate text boxes, and then click OK.

  • Request path: *.php
  • Module: FastCGImodule
  • Executable: C:\php\php-cgi.exe
  • Name: FastCGI

Figure 5: Add Script Map

15. Click OK, and then click Yes.

16. In the left panel, click on your server’s hostname, and then double-click on the Default Document icon.

17. From the Actions panel on the right, click Add.

18. Enter index.php as the new default document name, and then click OK.

19. Enter default.php as the new default document name, and then click OK.

20. In the left panel, click on your server’s hostname.

21. In the Actions panel on the right, click Restart.

22. Create a new text document, and save it as c:\inetpub\wwwroot\phpinfo.php with the following content:

<?php phpinfo(); ?>

23. You should now see the PHP information page at http://localhost/phpinfo.php.

Figure 6: PHP information page

Extensions

It is important to determine which extensions are needed by the applications that will be running and then to limit the installed extensions to only those. For a typical open-source application installation, for example, the following extensions are installed:

  • Database Extensions—Most open-source applications that use MySQL for a database engine use either the php_mysql or the php_mysqli extensions. For new development work, either of these extensions work well, or consider using the PDO versions of the MySQL driver (PDO is a PHP extension providing a data-access abstraction layer that can be used with a variety of databases); this extra layer of abstraction provides a richer set of object database functionality and controls. If Microsoft® SQL Server® (or an express version, such as Microsoft® SQL Server® 2008 Express or Microsoft® SQL Server® 2005 Express Edition) is the database engine, use the php_mssql extension for open-source applications. For new development work, use the PDO version of the SQL driver.
  • Image Handling Extensions—Many of the open-source applications that enable work with images make use of the GD2 extension – php_gd2, which has a number of good basic image manipulation application programming interfaces (APIs). Some applications use the ImageMagick application and libraries. There is also a php_exif library for working with the extended information that modern digital cameras store within the images.
  • Internationalization and Localization Extensions—The two most commonly used extensions for i18n and l10n are php_mbstring (Multi-Byte String) and php_gettext (Native Language Support). Many of the open-source applications use one or both of these.
  • Web Services Extensions—Choose the Web services extensions based on the services desired. For PHP, the SOAP extension is widely used. The XML-RPC extension is often used in conjunction with SOAP and other services.

PHP.INI File Settings

The Php.ini file provides PHP with configuration and environmental information. Below are a number of settings for the Php.ini file that help PHP work better with Windows.

 

Required Settings:

  • extension_dir = <PATH TO EXTENSIONS>
    The extension_dir needs to point to the directory where the PHP extensions are stored. The path can be fully qualified (for example, C:\PHP\ext) or relative (for example, .\ext). Extensions that are specified lower in the Php.ini file need to be located in the extension_dir. If the extensions specified are not in the extension_dir, then PHP will give a warning message at the start of script execution, and the application may show errors because of the missing functionality.
  • extension = xxxxxx.dll
    For each extension enabled, a corresponding extension= directive that tells PHP which extensions in the extension_dir to load at startup time is necessary.
  • log_errors=On
    PHP errors can also go through the PHP error logging facility. This can be used to send errors to a file or to a service (for example, syslog) and works with the error_log directive described below. When running under IIS, log_errors must be enabled with a valid error_log. Otherwise, FastCGI considers any startup messages (which may be benign) as an error condition, which generates an HTTP 500 return error code to the browser.
  • error_log=<path_to_error_log_file”
    The error_log needs to specify the fully qualified, or relative, path to the file where the PHP error log is stored. This file needs to be writable for the IIS service. The most common places for this file are in various temporary directories (for example, C:\inetpub\temp\php-errors.log). That puts the log in a place that IIS can use, and also keeps the log close to where PHP applications are running.
  • cgi.force_redirect = 0
    This directive is required for running under IIS. It is a directory security facility required by many other Web servers; however, enabling it under IIS will cause the PHP engine to fail on Windows.
  • cgi.fix_pathinfo = 1
    This lets PHP access real path info following the CGI specification. The IIS FastCGI implementation needs this extension set.
  • fastcgi.impersonate = 1
    FastCGI under IIS supports the ability to impersonate security tokens of the calling client. This allows IIS to define the security context that the request runs under.
  • fastcgi.logging = 0
    FastCGI logging should be disabled on IIS. If it is left enabled, then any messages of any class are treated by FastCGI as error conditions, which will cause IIS to generate an HTTP 500 exception.

 

Optional Settings:

  • max_execution_time=##
    This directive sets the maximum amount of time that can be taken executing any given script. The default is 30 seconds. Some applications need more time to process batch operations (for example, Gallery2 loading multiple images from a remote location). However, setting the execution time higher than 300 seconds is not advised because there are often other parts of the connection that cannot support such a long execution time.
  • memory_limit=###M
    The amount of memory available for the PHP process (in MB). The default is 128 MB, which is appropriate for most PHP applications.
  • display_errors=Off
    This directive determines whether to include any error messages in the stream that it returns to the Web server. If turned on, PHP will send the classes of errors that are defined with the error_reporting directive back to IIS as part of the error stream. Many of the open-source applications bypass error reporting by executing commands prefaced with @. This allows the applications to control error handling.
  • Mail functions
    PHP is configured by default to send outbound mail through an SMTP server located on the same system as the Web server. Note that most Windows installations usually have the Web and mail servers on separate systems.

Enable PHP Session State

1. In Windows® Explorer, create the session subdirectory in the PHP installation directory.

2. Right-click the session directory, and select Properties.

3. In the Security tab, click Edit.

4. Click Add, and enter IIS_IUSRS for Enter the object names to select.

5. Click OK.

6. Select the Modify permission check box, and click OK.

Figure 7: Permissions for session folder

7. Click OK in the Session Properties window.

8. Open php.ini in the PHP installation directory, and set the session.save_path setting to the session subdirectory:

session.save_path = “C:\php\session”

9. Save and close the file.

10. Click Start, and then select Command Prompt.

11. Type runas /user:administrator cmd.exe to enable elevated permissions.

12. Type iisreset at the command prompt, and then press the ENTER key.

Figure 8: IISRESET command

Note that PHP uses file-based session state by default. You can modify a number of additional session settings, including whether cookie or URL sessions should be used, and whether sessions are created on the first request or need to be explicitly created.

13. Test the session state by using Windows Explorer, navigate to C:\inetpub\wwwroot.

14. Create a folder and rename it phpapp.

15. Create session.php in the phpapp directory.

16. Paste the following into it:

<?php
session_start();
$counter = isset($_SESSION[‘counter’]) ? $_SESSION[‘counter’] : 0;
$counter++;
print “You have visited this page $counter times during this session”;
$_SESSION[‘counter’] = $counter;
?>

17. Save and close the file.

18. Start Internet Explorer, and navigate to http://localhost/session.php.

Figure 9: Using session state

19. Observe that the counter is 1.

20. Request http://localhost/session.php again, or press F5.

Figure 10: Using session state

21. Observe that the counter is 2.

Note: This article uses information from “Using FastCGI to Host PHP Applications on IIS 7.0 and Above” by Ruslan Yakushev, published on December 5, 2007.

 

If Not Then:

Assuming you’ve carried out steps 1 – 9 in the article you linked to and have your PHP files extracted to c:\php then complete the following steps using a cmd.exe command prompt:

Firstly we need to configure IIS Express and setup a handler for PHP

cd "\Program Files\IIS Express"

appcmd set config -section:system.webServer/fastCgi /+"[fullPath='C:\PHP\php-cgi.exe',arguments='',maxInstances='4',idleTimeout='300',activityTimeout='30',requestTimeout='90',queueLength='1000',instanceMaxRequests='200',protocol='NamedPipe',flushNamedPipe='False',rapidFailsPerMinute='10']" /commit:apphost

appcmd set config -section:system.webServer/handlers /+"[name='PHP-FastCGI',path='*.php',modules='FastCgiModule',verb='*', scriptProcessor='c:\php\php-cgi.exe']" /commit:apphost

Assuming your PHP website resides in c:\MyPHPWeb we create a site in IIS Express that listens on http://localhost:32701:

appcmd add site /name:"MyPHPApp" /bindings:http/*:32701: /physicalPath:"c:\MyPHPWeb"

Next start the site:

iisexpress.exe /site:MyPHPApp

And finally browse to your PHP page:

http://localhost:32701/test.php

 

 

IIS 7 Server on Windows 7: Localhost work but not local ip or external ip

Solution: Stop/ Set Firewall turn off in the Server PC and see the Magic !!!

Windows 7: (Computer Manager) MyComputer –> Manage –> Services and Application –> Internet Information Services (IIS) Manager –> PC Name –>Sites –> Default Web Site

Install Internet Information Services (IIS) Manager for Application Publication using Virtual Directory

 

 

Start or Stop the Web Server (IIS 7)

noteNote
You must be a server administrator to perform this procedure.

To start or stop a Web server


You can perform this procedure using the user interface (UI) or a command line. For information about opening IIS Manager, see Open IIS Manager (IIS 7).

  1. Open IIS Manager and navigate to the Web server node in the tree.
  2. In the Actions pane, click Start if you want to start the Web server or Stop if you want to stop the Web server.
  1. Open an elevated command-line window.
  2. At the command prompt, type net stop WAS and press ENTER; type Y and then press ENTER to also stop W3SVC.
  3. To restart the Web server, type net start W3SVC and press ENTER to start both WAS and W3SVC.

I need to run xampp. Xampp uses localhost as well. How can I turn off iis 7 so that I can run xampp?

stop and disable the www service

type services.msc from the run command prompt > scroll down to World Wide Publishing service.

or go to control panel > Administrative Tools > Services.msc > World Wide Publishing service.

Installing IIS 7 on Windows Windows 7 and Internet Information Services Manager to manage and configure IIS

Introduction

You can use the Microsoft® Web Platform Installer (Web PI) to easily install Internet Information Services (IIS), and applications that run on IIS. To learn more about the Web PI, see Learn about and install the Web PI.

If you choose to install IIS 7.0 or above manually, you can use this article for guidance.

Before You Begin

Ensure that you have installed one of the editions of Windows Vista or Windows 7 on which IIS 7 and above is supported before you proceed. Not all IIS features are supported on all editions of Windows Vista and Windows 7. Home Basic and Starter editions include only limited basic features of IIS. To see a list of which features are supported on the edition of Windows you are using, see one of the following:

Also be sure that you have administrative user rights on the computer. By default, you do not have administrative user rights if you are logged on as a user other than the built-in administrator, even if you were added to the local Administrators group on the computer (this is a new security feature in Windows Server® 2008 called Local User Administrator). Log on either to the built-in administrator account, or explicitly invoke applications as the built-in administrator by using the runas command-line tool.

Note that you can run runas /user:administrator cmd.exe so that every application you run from that command line will be elevated, eliminating the need to use the runas syntax from that command line.

If you are logged on to an account other than the built-in local administrator account, you may see the following security alert dialog box.

Figure 1: Windows Security (User Account Control)

Install IIS 7 or Above

1. To open the Windows Features dialog box, click Start, and then click Control Panel.

Figure 2: Windows Vista Start menu

2. In the Control Panel, click Programs.

Figure 3: Control Panel Home

3. Click Turn Windows features on or off.

Figure 4: Control Panel install options

4. You may receive the Windows Security warning. Click Allow to continue. The Windows Features dialog box is displayed.

Figure 5: Windows Security dialog box

5. Expand Internet Information Services. Additional categories of IIS features are displayed. Select Internet Information Services to choose the default features for installation.

Figure 6: Windows Features dialog box – IIS

6. Expand the additional categories displayed, and select any additional features you want to install, such as Web Management Tools.

Figure 7: Windows Features dialog box – IIS feature selection

7. If you are installing IIS for evaluation purposes, you may want to select additional features to install. Select the check boxes for all IIS features you want to install, and then click OK to start installation.

Figure 8: Windows Features dialog box – Installation selection

8. The progress indicator appears.

Figure 9: Progress indicator

9. When the installation completes, the Windows Features dialog box closes, and the Control Panel is displayed.

Figure 10: Control Panel Home page

10. IIS is now installed with a default configuration on Windows Vista or Windows 7. To confirm that the installation succeeded, type the following URL into your browser, http://localhost.

Figure 11: Default Web site

11. Next, you can use Internet Information Services Manager to manage and configure IIS. To open IIS Manager, click Start, type inetmgr in the Search Programs and Files box, and then press ENTER.

Figure 12: Default Web Site Home page

If you want to use ASP, Microsoft® ASP.NET, or PHP, install the modules needed to host these pages; this can be done during the installation of IIS or after the installation is complete.

Use Unattended Setup to Install IIS 7.0 and above

IIS can also be installed unattended on Windows Vista. For detailed instructions and scripts, see Using Unattended Setup to Install IIS 7.0 and Above.

How to Install Internet Information Services (IIS 7) on Windows 7 Ultimate

How to Install Internet Information Services (IIS 7) on Windows 7 Ultimate

internet-information-services-iis7-manager

If you want to install Microsoft Internet Information Server (IIS 7) on your new Windows 7 computer first time after working with IIS 6 for long years, I believe you will be surprised with the improvements and changes both in IIS and IIS installation process.

First of all Microsoft has renamed the IIS as Internet Information Services and is not now using Internet Information Server for IIS.
In this short guide I will summarize the steps of installing IIS 7 on Windows 7 in the way I had recently on my Windows 7 Ultimate Edition PC. I’m using this pc as a home pc but I work on my web projects at home so I run SQL Server 2008 R2 as well as IIS and host ASP.NET applications.

So if you want to install Internet Information Services (IIS 7) for a developer computer then you can follow me by reading my notes below.
I do not know the other editions but Windows 7 Proffessional edition and the Windows 7 Ultimate edition are able to install and run IIS 7.

IIS Installation

IIS 7 can be installed and features of IIS 7 can be added or removed by Windows 7 “Control Panel > Programs” management screen. You can add and install Windows 7 components and build in applications using the “Turn Windows features on or off” link.

iis 7 installation on windows 7

When the Windows Features screen opens and generates in a short time a list of Windows 7 features installed and configured on the current system and a list of Windows 7 features not installed yet.
When the list is completed drill down the Internet Information Services node.

 

Internet Information Services – IIS 7 World Wide Web Features

Application Development Features

I started with the World Wide Web Services and Application Development Features.
Since I’m an ASP.NET developer and aim to work with ASP.NET on IIS 7, I selected the checkbox next to ASP.NET. When you click on ASP.NET the following features will be automatically selected :

  • .NET Extensibility,
  • ISAPI Extensions and
  • ISAPI Filters.

iis7-application-development-features

Security

Then I opened the Security node and marked Windows Authentication beside Request Filtering.
I did not choose any other options since I do not think to develop using other authorization and authentication features in a short time.
So I keep them uninstalled. I can installed these features in future somehow.

iis-7-security-features-list

Common HTTP Features

From the Common HTTP Features, I choosed Static Content in order to serve static web pages in .htm and .html file extensions.
I did not select Directory Browsing feature to install as you will see, since directory browsing function is one of the basic ones that we remove from each web site on IIS 6 or other IIS versions.
I do not prefer to work with WebDAV now, so I keep WebDAV Publishing feature unchecked too.

installing-iis-7-common-http-features

Health and Diagnostics

From the Health and Diagnostics tools you will find new logging, monitoring and tracing tools helpful for keeping your web server secure. The Request Monitor and Tracing features will also help you to debug your applications by tracing the web request easily.

install-iis7-health-and-diagnostic-tools-and-features

Performance Features

In the IIS 7 Performance Features section there exists compression functions for static content and dynamic content. You can choose any compression feature.

installing-iis-7-performance-features

Internet Information Services – IIS 7 Web Management Tools

The IIS Management Console is a must if you are working with Internet Information Services. It is a handy web management platform which contains tools and serves methods for you to publish, manage, trace and log your web sites and web applications.

I checked the IIS Management Scripts and Tools. I believe these tools and scripts will make my life easier while working on IIS 7.

IIS Management Services is used to perform management of Internet Information Services from remote computers. If you want to perform management of your web server from remote computers, you should mark this option. Especially if you are installing IIS 7 on a web server, probably you will want to remote manage your IIS web server.

install-iis-7-web-management-tools

After you select all the necessary components, tools and features required for you click on OK button to start installing IIS 7 on Windows 7.
You will have wait for a few minutes while Windows 7 is installing IIS 7 and changing IIS 7 features.

installing-iis7-on-windows7-ultimate

After the Internet Information Services – IIS 7 installation is completed you can browse to the http://localhost in order to see if your IIS7 is installed and start running on your Windows 7 computer.
If IIS7 (Internet Information Services) is up and running the following static web page will be displayed on your browser.

iis-7-welcome-screen

You can open the Internet Information Services (IIS) Manager console by following the below path.

iis-7-management-console-path

Open “Control Panel > System and Security > Administrative Tools” then click on Internet Information Services (IIS 7) Manager icon to open the IIS 7 management console.

I believe web developers and IIS administrators installed IIS before will not face difficulty installing IIS 7 on Windows 7

How to: Create and Configure Virtual Directories in IIS 7.0 (also 6.0)

How to: Create and Configure Virtual Directories in IIS 7.0

.NET Framework 4

By using IIS Manager, you can create a virtual directory for an ASP.NET Web application that is hosted in IIS 7.0. A virtual directory appears to client browsers as if it is in the Web server’s root directory, even though it can physically reside somewhere else. This approach enables you to publish Web content that is not located under the root folder of the Web server, such as content that is located on a remote computer. It is also a convenient way to set up a site for local Web development work because it does not require a unique Web site for each virtual directory.

This topic explains how to create a virtual directory and configure it to run ASP.NET pages on versions of that have IIS installed and on Windows Server 2008. For information about how to configure a virtual directory in IIS 5.0, 5.1, and IIS 6.0, see How to: Create and Configure Virtual Directories in IIS 5.0 and 6.0.

You must create a virtual directory as part of an existing IIS Web site. This can be either the default Web site that is created when IIS is installed, or a Web site that you have created. For additional details about how to install and configure IIS and about how to create a Web site, see the IIS Help or the online IIS product documentation on theMicrosoft TechNet  Web site.

Follow one of the procedures in How to: Open IIS Manager topic to open IIS Manager. You can then create a virtual directory.

To create a virtual directory by using IIS Manager

  1. In IIS Manager, expand the local computer and the Sites folder, and then find the Web site that you want to add a virtual directory for. Use the following steps:
    • For , right-click the site or folder where you want to create the virtual directory, and then click Add Virtual Directory.
    • For Windows Server 2008, right-click the site or folder where you want to create the virtual directory, click Manage Web Site, and then click Add Virtual Directory.
  2. In the Add Virtual Directory dialog box, specify the following information:
    • Alias. Type a name for the virtual directory. Choose a short name that is easy to type, because the user types this name to access the Web site.
    • Physical Path. Type or browse to the physical directory that contains the virtual directory. You can select an existing folder or create a new one to contain the content for the virtual directory.
  3. To provide credentials to connect to a UNC path, click the Connect as button.
  4. Click OK.

For more information, see Managing Virtual Directories in IIS 7.0 .

If ASP.NET functionality is enabled, when you create a virtual directory, it is already configured to run ASP.NET pages. For more information about how to enable ASP.NET functionality in IIS 7.0, see Running Web Applications on Windows Vista with IIS 7.0 and Visual Studio or Running Web Applications on Windows Server 2008 with IIS 7.0 and Visual Studio. The next configuration tasks you might want to perform are to configure security and authentication for your virtual directory.

To configure security for a virtual directory for an existing account

  1. In IIS Manager, select the virtual directory that you want to configure, and then click Edit Permissions in the Actions pane.

    The virtual directory’s Properties dialog box is displayed.

  2. Click the Security tab.
  3. Click Edit.

    The Permissions dialog box is displayed.

  4. Select an existing account in the Group or user names list.
  5. Select the appropriate permissions check boxes from the Permissions list for the selected group or user, as required for your virtual directory security.
  6. Click Apply to apply the changes.
  7. Click OK to close the Permissions dialog box.
  8. Click Apply to apply the changes in the Properties dialog box.
  9. Click OK.

To configure security for a virtual directory for an new account

  1. In IIS Manager, select the virtual directory that you want to configure, and then click Edit Permissions in the Actions pane.

    The virtual directory’s Properties dialog box is displayed.

  2. Click the Security tab.
  3. Click Edit.

    The Permissions dialog box is displayed.

  4. Click Add to add an account.

    The Select Users, Computers, or Groups dialog box is displayed.

  5. Add a user, computer, or group as required for you virtual directory security.
  6. Click OK to close the Select Users, Computers, or Groups dialog box.
  7. Select the appropriate permissions check boxes from the Permissions list for the new user, computer, or group, as required for your virtual directory security.
  8. Click Apply to apply the changes.
  9. Click OK to close the Permissions dialog box.
  10. Click Apply to apply the changes in the Properties dialog box.
  11. Click OK.

To configure authentication for a virtual directory

  1. In IIS Manager, select the virtual directory that you want to configure.
  2. In Features View, double-click Authentication.
  3. Select the authentication type to configure, and in the Actions pane make sure Enable is selected in order to enable the authentication type.

    If the authentication type is already enabled, the Actions pane enables you to disable or edit authentication configuration.

  4. In the Actions pane, click Edit or Advanced Settings to configure additional properties for the authentication type you selected.

    The actions available in the Actions pane vary depending on the authentication type you selected. For example, if the Anonymous Authentication module is installed and is enabled, you can click Edit to edit additional properties of anonymous authentication. If the Window Authentication module is installed and is enabled, you can click Advanced Settings to edit properties of windows authentication.

For more information about configuration authentication, see Configuration Authentication in IIS 7.0 . For a list of other common administrative tasks, see Common Administrative Tasks .

Creating Virtual Directories in IIS 6.0 (IIS 6.0)

In most cases, the content you publish to your Web or FTP site is located in a root or home directory on your computer, such as C:\Inetpub\Wwwroot\. However, there might be instances when the content is located somewhere else, or even on a remote computer.

To publish from any directory not contained within your home or root directory, you can create a virtual directory. A virtual directory is a directory that is not contained in the home directory but appears to client browsers as though it were.

You can create a virtual directory through IIS Manager or by using Windows Explorer. Additionally, you can create a Web virtual directory by using the Iisvdir.vbs script, and a FTP virtual directory by using the Iisftpdr.vbs script.

  Important

You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type runas /user:Administrative_AccountName “mmc %systemroot%\system32\inetsrv\iis.msc”.

Procedures

To create a virtual directory by using IIS Manager

1. In IIS Manager, expand the local computer, expand the Web Sites or FTP Sites folder, right-click the site or folder within which you want to create the virtual directory, point to New, and then click Virtual Directory. The Virtual Directory Creation Wizard appears.
2. Click Next.
3. In the Alias box, type a name for the virtual directory. (Choose a short name that is easy to type because the user types this name.)
4. Click Next.
5. In the Path box, type or browse to the physical directory in which the virtual directory resides, and then click Next.
6. Under Allow the following permissions, select the check boxes for the access permissions you want to assign to your users, and then click Next.

  Important

For security reasons, when selecting access permissions, consider allowing only the default Read permission. By restricting permissions in this way, you can help avoid attacks against your Web site by malicious users. For more information about setting access permissions, see Securing Virtual Directories and Access Control in Help and Support Center for Windows Server 2003.

7. Click Finish. The virtual directory is created below the currently selected folder level.

To create a virtual directory by using Windows Explorer

1. Open Windows Explorer.
2. Right-click the folder you want to be a virtual directory, and click Sharing and Security.
3. Click the Web Sharing tab.
4. Click Share this folder.
5. In the Alias box, type the name for the virtual directory.
6. Click OK twice.

To create a Web virtual directory by using the Iisvdir.vbs script

1. From the Start menu, click Run.
2. In the Open box, type cmd, and then click OK.
3. At the command prompt, type the following:

cscript %SystemRoot%\system32\iisvdir.vbs /create SampleWebSite[/PathVirtualDirectorydrive:\path

where SampleWebSiteVirtualDirectory, and path is the physical directory, as appropriate.

For more information about creating Web virtual directories by using the Iisvdir.vbs command and its parameters, type the following at the command prompt: iisvdir /create /?.

To create an FTP virtual directory by using the Iisftpdr.vbs script

1. From the Start menu, click Run.
2. In the Open box, type cmd, and then click OK.
3. At the command prompt, type the following:

cscript %SystemRoot%\system32\iisftpdr.vbs /create FTPSite[/PathVirtualDirectory drive:\path

where FTPSiteVirtualDirectory, and path is the physical directory, as appropriate.

For more information about creating FTP virtual directories by using the Iisftpdr.vbs command and its parameters, type the following at the command prompt: iisftpdr /create /?.