Warning: this is an advanced scenario for WebMatrix. If you are not comfortable with the command prompt or inspecting large lists of files for changes, this post is not for you. A couple weeks ago, I setup a WordPress blog using WebMatrix and published it to Applied Innovations. Since then, I’ve been making changes to the site on the host using the WordPress admin. Today, I wanted to pull those changes back down to my computer so I can work on my site template locally.  But I want to work on it with the current set of plugins, configuration settings, and templates from the live site. WebMatrix makes it really easy to deploy your site to a host. But the current beta does not support copying a site from the host down to your local computer. However, WebMatrix does use a very powerful deployment technology underneath the hood called Web Deploy. Because all the hosts that support WebMatrix implement the Web Deployment service, you can use all the features of the Web Deploy tool at the command line to interact with their service. Web Deploy provides several different operations (called verbs). You can dump a list of files from your site, get dependences and settings for a site or entire server, and you can sync files and settings between two computers or sites. In order to pull all the changes in the host back down to my computer, I used the sync verb. The Web Deploy command is called MSDeploy.exe and is located at C:\Program Files\IIS\Microsoft Web Deploy. If you run the MSDeploy.exe with no parameters, it will list out all of the supported verbs, objects and settings available for the tool.

Synchronize the Site Files

To sync files from my host, I typed the following command: (Split for readability, but should all be on one line)

"C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe"  
    -verb:sync
    -source:iisApp=drewby,
               wmsvc=https://web01.appliedi-labs.net:8080/msdeploy.axd,
               username=[USERNAME],
               password=[PASSWORD]
    -dest:iisApp="[MY WEB SITES]\wordpress”
    -skip:absolutePath=wp-config.php

  The first parameter (-verb) tells Web Deploy to use the verb of sync. The second parameter (-source) tells Web Deploy that I want to sync from the site on Applied Innovations server. The source is an IIS application (iisApp) with the name drewby. Replace drewby with your site name. Applied Innovations provided the server name and port. Replace [USERNAME] and [PASSWORD] with your username and password. The third parameter (-dest) tells Web Deploy to sync to the IIS application located at the directory where you created your WebMatrix site. Replace [MY WEB SITES] with wherever you store your web site projects. It is probably something like C:\Users\USERNAME\Documents\My Web Sites. The final parameter (-skip) tells Web Deploy to skip the wp-config.php which contains the local application configuration for WordPress. For example, this contains the database connection information. I didn’t want to overwrite my local database connection. When you execute this command, Web Deploy will connect to the server and compare all the files on the server with the files on your computer. It will add, update or delete any files that are different than whats on the server. If you want to see what Web Deploy is going to do before it applies any changes, you can add one more parameter called –whatif. This will list out all of the actions that it would take based on the comparison, but not actually make the changes.

Synchronize the Database

You can also sync your database for WordPress. If you are using SQL Server, the functionality is built into Web Deploy. If you are using MySql, then you need to download an additional object type for Web Deploy called dbFullMySql. You can download this add-on here and follow the directions for adding it to the Web Deploy directory. Once that is added, execute this command: (Split for readability, but should all be on one line)

"c:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe"  
    -verb:sync
    -source:dbFullMySql="Server=mysql01.appliedi-labs.net;
               Database=drewby_wordpress;
               Uid=[USERNAME];
               Password=[PASSWORD]"
    -dest:dbFullMySql="Server=localhost;
               Database=wordpress;
               Uid=[USERNAME];
               Pwd=[PASSWORD]"

You need to update the parameters in the connection string with your database server, database name, username and password for both the source and the destination. When you execute this command, Web Deploy will dump the source database into a script and then execute that script against the destination database.

Fix the WordPress SiteUrl

One last thing that you need to do is update the siteurl and home URL stored in the synced database. These were updated when you synced the database down to your computer. If you do not fix this, when you try to login to your blog on your local computer, you’ll be redirected to the instance deployed on your host. image You can use WebMatrix to do this. Open your site in WebMatrix. Click the Databases button in the left pane. If you configured WordPress with WebMatrix, you’ll see your database listed. Otherwise, click New Connection in the ribbon and connect to your database. Expand Tables and double-click the wp_options table to open it. Locate the row with option_name set to siteurl. Update the option_value column to be the URL of your local WebMatrix site. For example, mine was http://localhost:11489. Locate home and set it to the same URL. image Now you have a local version of WordPress with identical configuration as the one hosted on the web.