Internet Information Services (IIS) by Microsoft serves as a platform for hosting websites and web applications. It is natively included in Windows operating systems, offering an intuitive interface for overseeing websites and web applications. Additionally, IIS caters to advanced users and administrators by offering management capabilities via the Command Prompt.
This guide will walk you through the steps of establishing a website and an application pool within IIS through the Command Prompt.
Step 1: Open Windows Command Prompt
The first step in creating a website and application pool in IIS using the Command Prompt is to open the Command Prompt itself. To do this, press the Windows key + X and select the “Command Prompt (Admin)” option. If prompted, click “Yes” to grant administrative permissions.
You can also press the “WINDOW” button and then search for “Command Prompt”. In the search list, right-click on “Command Prompt” and click “Run as administrator”.
On the command prompt, navigate to the C:\Windows\System32\inetsrv directory.
cd c:\Windows\System32\inetsrv
Step 2: Installing IIS
If IIS is not already installed on your system, you will need to install it. To do this, type the following command in the Command Prompt and press Enter:
dism /online /enable-feature /featurename:IIS-WebServer /all
Step 3: Create Application Pool in IIS
IIS App Pool is used for grouping sites to use similar configuration settings or prevent other applications to use resources of one application by other applications. Use one of the below options as per your requirements
- App Pool with Default Settings
Use the following command to create an Application Pool named “myAppPool” with default settings of IIS.
appcmd add apppool /name:MyAppPool
- App Pool with Specific Settings
If you want to use different settings for your App Pools, use the command below. Change managedRuntimeVersion as per your requirements v1.0, v1.1, v2.0 or v4.0.
appcmd add apppool /name:MyAppPool /managedRuntimeVersion:v2.0 /managedPipelineMode:Integrated
Step 4: Create a Website in IIS
Once the application pool is created, you can now create a website in IIS. To do this, use the following command:
appcmd add site /name:MyWebsite /physicalPath:C:\inetpub\wwwroot\MyWebsite /bindings:http/*:80:example.com /apppool:MyAppPool
Replace “MyWebsite” with the desired name for your website and “C:\inetpub\wwwroot\MyWebsite” with the physical path where the website’s files will be stored. Also, replace “example.com” with your site domain name.
Step 5: Start the Website
The final step is to start the website. Use the following command to start the website:
appcmd start site /site.name:MyWebsite
Replace “MyWebsite” with the name of your website.
Step 6: Create Subdirectory Application (If Required)
You can add a subdirectory application to your existing website. For example, to configure a URL like http://example.com/blog, the /blog is the subdirectory application configured under the example.com website. To create this create execute the following command. Assuming the document root for the blog is C:\inetpub\wwwroot\blog.
appcmd add app /site.name:example.com /path:/blog /physicalPath:C:\inetpub\wwwroot\blog
Step 7: Changing the Application Pool (If Required)
You can also change the Application Pool of any website using appcmd command. Use following command to change application pool of site example.com and set App Pool to myAppPool
appcmd set site /site.name:example.com /[path='/'].applicationPool:myAppPool
To change the Application Pool for a subdirectory URL use the following command.
appcmd set site /site.name:example.com /[path='/blog'].applicationPool:myAppPool
Conclusion
In conclusion, creating a website and application pool in IIS using the Command Prompt is a simple process that can be completed in just a few steps. This method is particularly useful for advanced users and administrators who want to automate the process of creating websites and application pools or for those who prefer to use the command line interface. By following the steps outlined in this article, you can easily create a website and application pool in IIS using the Command Prompt.
3 Comments
The command line with “appcmd set site” seems wrong. An ending “/” is required in the site name.
See https://stackoverflow.com/questions/4470671/associate-an-application-pool-to-site-with-appcmd
Can you tell us more about this? I’d love to find out some additional
information.
This very useful