How do I change the physical path of web site in IIS7 with APPCMD?
Asked Answered
M

5

40

I need to change the physical path of a web site through the command line via the appcmd.exe tool, but I can't figure out the syntax. Can someone help?

Marduk answered 24/10, 2009 at 22:10 Comment(0)
E
53

This is how you should do:

C:\Windows\System32\inetsrv>appcmd set vdir "MySite/" -physicalPath:"C:\inetpub\temp"

Note: "MySite/" is a name of your virtual directory so if your virtual directory is under default web site you're likely have to set "Default Web Site/MySite/"


As for figuring out how to do other appcmd commands just type: appcmd set vdir /?

and you'll get all the info on what you can do to set your virtual directory.

Even more specifically, if you want to know what settings you can change for the specific virtual directory type:appcmd set vdir "MySite/" /?

These examples are just for virtual directory by they apply to other appcmd commands

Hope this helps

Epigoni answered 31/10, 2009 at 12:13 Comment(5)
This did not answer the question. As stated, I need to change the physical path of a web site, not a virtual directory. Also, the question was that I cannot figure out the syntax. I'm aware of /?. The help outputted with that does not clearly describe how the syntax should look.Marduk
@Frank Edwards - 1. I assume you haven't tested my answer 2. In IIS 7.0, each site must have an application and each application must have a virtual directory. The root virtual directory of your site points to the physical path of the site. To better understand the concept of site / application / virtual directory I suggest reading this article: learn.iis.net/page.aspx/150/… especially the section with the title IIS 7.0 Configuration: <sites> SectionEpigoni
if you create a site with appcmd add site /Name:test you will not be able to add a phyiscalPath later, you must create the site with(at least) appcmd add site /Name:test /physicalPath:"C:\inetpub\wwwroot\mysite" which results in SITE object "test" added APP object "test/" added VDIR object "test/" added which then allows you to change the vdir phyisicalPath at a later dateEverson
Yeah, um, as James notes, @PaulGo this answer does exactly what you were asking for me as long as I run from an administrator elevated command prompt. Green check incoming!Hebbel
@Hebbel This question was posted so long ago (11 years!) that I have no clue what I was even asking or why, so I decided to just green check this answer because it seems like it's the one that's generating the most value for people...Marduk
L
15

The following works for me on IIS 7.5. It changes the physical path of the website:

appcmd set site /site.name:"website name" /application[path='/'].virtualDirectory[path='/'].physicalPath:"C:\new\path"

Type the following to get a complete list of properties that you can set:

appcmd set site /site.name:"website name" /?

Reference

Luisluisa answered 19/2, 2014 at 10:53 Comment(0)
O
7

The answer above is correct. Here's what it might look like for setting the default web site and a couple of other virtual directories. We want the default web site to be on D: with a special unique path name for the app, but two of the virtual directories belong back on C: with their own paths:

C:\windows\system32\inetsrv\appcmd.exe set vdir "Default Web Site/" -physicalPath:"D:\MyUniquePath"
C:\windows\system32\inetsrv\appcmd.exe set vdir "Default Web Site/OtherWebSite" -physicalPath:"C:\OtherWeb\ApplicationServer\web"
C:\windows\system32\inetsrv\appcmd.exe set vdir "Default Web Site/ExtraPlugins" -physicalPath:"C:\OtherWeb\ApplicationServer\plugins"

The syntax is easy, but determining the exact string that appcmd takes for the virtual directory can be tricky.

Orris answered 6/10, 2011 at 12:43 Comment(0)
D
7

And in case you are trying to change the physical path of a Web Application, here is an example changing the Web Application "Spockadoodle" that is created under Web Site "Default Web Site" to have the physical path "C:_junk".

appcmd set app /app.name:"Default Web Site/spockadoodle"  -[path='/'].physicalPath:c:\_junk

I figured this out by running the command:

appcmd set app /app.name:"Default Web Site/spockadoodle"  /?

and in the output I observed

ERROR (message:-path
-applicationPool
-enabledProtocols
...
-[path='string'].physicalPath

and prior to that, in the output of the command

appcmd set apps /?

the output mentioned:

Example: appcmd set app "Default Web Site/" /enabledProtocols:http

Sets the "enabledProtocols" property of the application "Default Web
Site/".

So, from the example citing how to set "enabledProtocols", I substituted the example of [path='string'].physicalPath

To know the value for the attribute expression [path='string'] I observed in the output of the command

appcmd list app "Default Web Site/spockadoodle" /config

output shows that the Web App Spockadoodle has path attribtue value "/":

<application path="/spockadoodle" applicationPool="IRServices">

<virtualDirectoryDefaults />

<virtualDirectory path="/" physicalPath="c:_junk" />

</application>

Also, I figured out to use the /app.name identifier from examples on the website http://www.iis.net/learn/get-started/getting-started-with-iis/getting-started-with-appcmdexe

Dicks answered 28/10, 2014 at 15:7 Comment(1)
Some explanations were very helpful. Thank you.Kessiah
H
3

To get a list of virtual directories by site and app name to help ensure you are attempting to set the right thing.

C:\Windows\System32\inetsrv\appcmd.exe list apps /config /xml

optionally pipe that |more and/or mode con cols=160 this regex pulled out the parts I wanted

var q= from siteApp in config.XPathSelectElements("appcmd/APP")
        let appName=siteApp.Attribute(XNamespace.None+"APP.NAME").Value
            from app in siteApp.XPathSelectElements("application")
        let appPath=app.Attribute(XNamespace.None+"path").Value
        let pool=app.Attribute(XNamespace.None+"applicationPool").Value
        let vd=app.XPathSelectElements("virtualDirectory[@path]")
        let virtuals=vd.Select (v => new{VirDir=v.Attribute(XNamespace.None+"path").Value,PhysicalPath=v.Attribute(XNamespace.None+"physicalPath").Value})
        let xvirtuals=virtuals.Select (v => new{ VirDir=v.VirDir,
            PhysicalPath=v.PhysicalPath,
            EnvRoot=v.PhysicalPath.ToString().StartsWith("%")})
        select new{AppName=appName,AppPath=appPath, Pool=pool,Virtuals=xvirtuals};

so then for a specific site it becomes appcmd.exe set vdir "DefaultWebSite/jms" -physicalPath:"c:\inetpub\wwwroot\mytargetPath"

here's the variable substitutions:

appcmd.exe set vdir " + appName + virt.VirDir + " -physicalPath:" + targetPath+"

and to look at the config settings for just that site:

    C:\Windows\System32\inetsrv\appcmd.exe list apps /config /xml /path:/jms

another usage to be aware of:

    C:\Windows\System32\inetsrv\appcmd.exe list apps /metadata /config:* /xml
Handedness answered 4/9, 2012 at 20:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.