Either you want to test something without affecting your live website or you need to move to another hosting provider, it is sometimes necessary to move a DotNetNuke installation to a new server. In this tutorial, I will show you how to proceed correctly.
This process is done in 4 steps
- Backing up the original files and database
- Restoring the files and database to the new host
- Configuring the database on the new host
- Modifying the Web.Config file to connect to the new database
So let's get started:
Tools we will use
- For working with the database I will use SQL Server Management Studio 2008, but your version may vary. The free express edition will do just fine.
- You can transfer the files with whatever tool you like, in my case I will use a free FTP client called Filezilla, they have a client and a server in case you don't already have an FTP server on the destination machine
- You can use whatever zip utility you like, even the built-in Windows zip functionality, however I find that 7-zip has a better performance and options and it is free and open source too
- For editing text files, I tend to prefer to use Notepad++ which will highlight code for many popular file formats and is also free, but you can do the same with any plain text editor such as the windows notepad. Do not use word or wordpad, these tools are not made to work with plain text files.
Step 1: Getting our original site backups
- Backing up the files: We need to take a full backup of all the files in the original site folder. This step is very simple, you just have to find your site root folder and compress all the files into a zip or similar file. If you are not sure in which folder your DotNetNuke installation resides, you can login as a host to your DotNetNuke website, then navigate to Host->Host Settings and you should see the root folder of your site next to Physical Path:
Backing up the database: Then we need to take a "Copy only backup" of the database. This type of backup will backup your site database without affecting any existing backup strategy in place in your SQL Server. Also, a "Copy only backup" will be a full backup (not incremental), so it will be usable to restore to another SQL Server that does not yet have a database with that name
To create a "Copy only Database Backup", open SQL Server Management Studio, login and right click on your database.
Then select Tasks->Backup
In the new popup, make sure you select Full in Backup type, tick the Copy only backup checkbox and take note of the file location (or choose a new one, be removing the existing one and adding another, there should be only one file listed in the Destination box). Finally click OK and make sure the operation is successful.
If you are not sure which database it is, you can also see it in DotNetNuke in Host->Dashboard in the Database tab, at the end where the database files are shown, the database name will show there.
- Copy the files: Now use whatever method you prefer to transfer these two files to the destination server (one compressed .zip or .7z file containing your files and one .bak file containing your database backup).
Step 2: Restoring your files and database on the new server
Restoring your files: Simply unzip your archive to the new website folder.
Restoring your database:
In SQL Server Management Studio, right-click on Databases and then go to Tasks->Restore Database...
In the new window, enter the database name you want to use in the To destination field. The name could be the same or a different name.
- Then select From device and click on the ... button and locate your file
- The backups available in that fil will show in the list on the bottom, you probably only have one, but if many are showing, select the most recent one having a type of Full (Copy only)
- Finally, click OK and make sure you get a success message
That restores the database, however we still have a problem that the databaseOwner user probably does not exist on the new server, so we will have a problem to connect to our database if not using Windows Authentication. We will fix that in the next step.
Step 3: Configure the database on the new host
Ok, so now we have a few things to fix on the new database, the database user and the portal alias that will be used.
- Fixing the user account: The problem we are facing is that the user account used by DotNetNuke to access the database is included in the backup but a matching login does not exist on the new SQL Server. We call this situation an "Orphan user". It used to be a lot of trouble to fix, and I used to just create a new user in the new server. However, I have learn a new trick just today using a system stored procedure that handles this for us easily. So I will now explain that procedure:
- Open SQL Server Management Studio and connect to your server
- Click on the New Query button
- Remove any code in that window and type the following, replacing databasename by your new database name
That will show you a table containing all orphan users for that database (normally only one), take note of or copy that username
- Now we will create a new login with that username, right-click on Security in your server objects and click on new->login
- In the new window, type or paste the username in the Login name field, select the SQL Server authentication radio button and make sure Enforce password policy is NOT checked, finally select your database in the Default database field and click OK.
- We now have a user (in the database) and a login (in the server) that have the same user name, however we still need to tell the Server that they belong together. To do that, write the following code in the query window, replacing databasename and username by your database name and your username (from previous step):
If done properly, you should receive a message such as: The row for user 'username' will be fixed by updating its login link to a login already in existence... + some statistics
- Now, try to disconnect from the SQL Server and reconnect with the created login, if everything went fine, you should be able to login and access your database
- Fixing the site alias: The site alias is the domain name used to access your website, we need to add the domain name or change the domain name in the DotNetNuke database so it responds to it
- In SQL Server Management Studio, open your database and look for a table named dbo.PortalAlias
- Right-click on it and click on Edit top 200 rows, then add a record with the following info:
PortalId: 0 (or if you have many portals, repeat this operation for for every portal id you see in this table)
HTTPAlias: enter the domain name you want your website to respond to
CreatedByUserId: -1 (-1 means system, so no particular user will be assigned with this modification)
CreatedOnDate: the current date using the format yyyy-mm-dd (unless your database does not use the neutral culture in which case enter the date like you see it in the other rows
LastModifiedByUserId: -1 (also meaning system like for the CreatedByUserId)
BrowserType: (you may not have that field, if you do have it leave it blank)
Skin: (you may not have that field, if you do have it leave it blank)
CultureCode: (you may not have that field, if you have it leave it blank)
IsPrimary: (you may not have that field, if you have it, type True)
- Next we need to check if we need to change the default alias. Look for a table named PortalSettings, right-click on it and click on Edit Top 200 rows
In the table that shows up, scroll and look in the column SettingName for a setting name DefaultPortalAlias, if you find it (you may have more than one if your site has many portals) change the domain in the column SettingValue to your new domain name.
Step 4: Modifying the Web.config file to connect to the new database
The Web.config file contains all DotNetNuke and ASP.Net configuration options. One of these options is the database connection string. If we leave it like that your site will try to connect to the old database server and may either fail or show the info from the original site and not our new copy. So we will change that like so:
- Navigate to your website root folder (when you extracted the .zip or .7z file) and locate the web.config file
- Open that file with a plain text editor (Windows Notepad, Notepad++, Programmers Notepad, etc.) Warning, do not open with Microsoft Word, Wordpad or any other rich-text editor.
- We have two lines to modify, one is in the <connectionStrings> section and starts with <add name="SiteSqlServer", the other is in the <appSettings> section and starts with <add key="SiteSqlServer"
Replace (local) by your SQL server name, or leave local or user localhost, depending on how you access your new SQL Server
<!-- Connection String for SQL Server 2005/2008 -->
"Data Source=(local);Initial Catalog=databasename;User ID=userid;Password=password"
<!-- Connection String for SQL Server 2005/2008 - kept for backwards compatability - legacy modules -->
"Data Source=(local);Initial Catalog=databasename;User ID=userid;Password=password"
Replace databasename for your new database name (if you have created a new name, if not leave it
Replace username for your user name for that database (only if you have changed it)
Replace password for your password also only if you have changed it
Repeat for each of the two yellow lines above
Finally, just open a browser and navigate to your domain name and DotNetNuke should start. Note that it may take some time for the application to recompile and load on the first visits to the site. If you get a timeout on the first visit, just refresh the page.
If you get other errors, note them and either comment this post here or post in the DotNetNuke Forum, or search the error on google, etc.
This post is a bit long, but when you get used to it, the file transfer is usually the longest step in the process. If anything is unclear or you have questions, feel free to leave a comment!