These instructions walk through the steps of installing the FHIR API on a Windows Server. The setup includes intalling a SQL server, running the application using IIS, setting up a domain name, and certificates.
Initial Install Instructions
Update Instructions
Update Identity Credentials
Log Viewing
Potential Issues
IIS Resources
- Setting up Windows Server
- Install Internet Information Services (IIS) on the Windows server
- Install the .NET module for IIS https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-6.0
- Make sure you have a way to access the Windows filesystem from your local machine
- Build the project
- On your local machine, clone the git repo https://github.com/nightingaleproject/Reference-NCHS-API
- Checkout the tagged version you want to install
- From the project root directory, run
dotnet publish —configuration release
on your local machine - Copy all files in messaging > bin > release > net6.0
- Paste the files to a folder on the new Windows Server
- Create and update all three appsettings and web.config files in the project folder on the new server
- appsettings (update the database server name)
{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information", "Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information" } }, "ConnectionStrings": { "NVSSMessagingDatabase": "Server=<db-server-name-here>.cdc.gov;Database=nvssmessaging;Integrated Security=SSPI;" } }
- web.config
<?xml version="1.0" encoding="utf-8"?> <configuration> <location path="." inheritInChildApplications="false"> <system.webServer> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /> </handlers> <aspNetCore processPath="dotnet" arguments=".\messaging.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" /> <environmentVariables> <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="<environment>" /> </environmentVariables> </system.webServer> </location> </configuration>
- Install certificates
- If you plan to run multiple apps on the same machine (ex. Test and Dev) request DNS names for each
- Request an external certificate
- Make sure the new cert is installed on the machine
- Create the IIS application
- Configure each new site in IIS https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-6.0&tabs=visual-studio
- Point the app to the folder created in Step 2 that holds all the release files on the server
- Configure HTTPS and point to the cert installed in step 3
- Do not start the server until the SQL database is up and running
- Set up SQL server
- Create a new sql server
- On your local machine in the project directory, run
dotnet ef --project messaging migrations script
to get the full sql script including all migrations - Execute the sql script on the new sql server to initialize the db
- Run the IIS application
- Once the app is configured and the SQL database is running, go to the IIS application and hit "start" in the right side menu
- Testing
- Once the API is up and running, test posting a request to the endpoint
curl -X POST https://<server-host-name>/MA/Bundle -- header "Content-Type: application/json" --data "@path\to\test\MessageSubmission.json"
- Once the API is up and running, test posting a request to the endpoint
- SQL Authentication
- In the appsettings.json file, add
Integrated Security=SSPI;
- In IIS, set the Site authentication to
Anonymous Authentication=Enabled
andASP.NET Impersonation=Disabled
- Create a service account with Read/Write permissions for the database, ex
Domain\NVSSMsgAPI_SvcAcct
- Set up impersonation at the Application Identity Pool level
- Go to the pool's advanced settings
- Click the Identity field
- Select custom identity
- Enter the credentials for the account from step 1 into the form
- Add the account from step 1 to the
batch logon
permissions group - Add the account from step 1 to the
IIS_IUSRS
group - Add the account from step 1 to the
Log on as a service
group - Give the account from step 8.3 permissions to access the application folder
- Set up HSTS
- In the appsettings.json file, add
- In gitbash, or your preferred command line tool, navigate to the Reference-NCHS-API root directory
- Use
git fetch
to pull the latest code from https://github.com/nightingaleproject/Reference-NCHS-API - Use
git checkout <vx.x.x>
to checkout the newest tagged verion on your local machine, see the list of tags here - If there are migrations to apply for this verions, run
dotnet ef migrations list
to get a list of past migrations. Otherwise go to step 5.- If there are new migrations to apply for this version run
dotnet ef --project messaging migrations script <name-of-last-applied-migration>
to get the SQL script for all migrations after the last applied migration
- If there are new migrations to apply for this version run
- From the project root directory, run
dotnet publish —-configuration release
on your local machine.- If you are deploying a debug version, run
dotnet publish --configuration debug
instead. This will enable the debug logging.
- If you are deploying a debug version, run
- Copy the all files in
messaging > bin > release > net6.0
- If you are deploying a debug version, copy all the files in
messaging > bin > debug > net6.0 instead
- If you are deploying a debug version, copy all the files in
- Use your file explorer to connect to the remote server's filesystem (
\\ASTV-NVSS-API
for test and dev,\\ASPV-NVSS-API
for prod) and paste all the files from step 6 to a new folder underUsers > Public
. Name the new folder using the version number of the software, ex.NVSS-FHIR-API-v1.2.0
. The file transfer will take a few mintues. - Connect to the server via rdp at https://pvwach.cdc.gov
- On the remote server, open the file explorer and copy the folder created in step 7. Paste the contents into a new folder under
D:/WebApps/
. If you are deploying dev and test, you will need to create two new folders,D:/WebApps/NVSS-API-TEST-vx.x.x
andD:/WebApps/NVSS-API-DEV-vx.x.x
and paste the contents into both folders. - Copy all three
appsettings.json
,appsettings.Test.json
, andappsettings.Development.json
files and theweb.config
file from theNVSS-API-TEST
folder and paste them in the newNVSS-API-TEST-vx.x.x
folder. Do the same forNVSS-API-DEV
andNVSS-API-DEV-vx.x.x
. The config files are different for dev, test, and prod so make sure you copy from the correct folder. - If you are applying migrations, complete the following steps. Otherwise skip to step 12.
- From your local machine, connect to the dev server database in visual studio code using server explorer
- Select Microsoft SQL Server
- server name:
dstv-infc-1900.cdc.gov
,dsdv-infc-1900.cdc.gov
- database name:
NVSSMESSAGING
- Paste the SQL code from step 4.1 in a new query and run to apply the migration
- From your local machine, connect to the dev server database in visual studio code using server explorer
- Before you update the API, double check what the current version is by navigating to the metadata endpoint, ex. for test is
https://test.astv-nvss-api.cdc.gov/MA/metadata
. The API version will be specified in the json response. - On the remote server, run the IIS application (Internet Information Services)
- Select ASTV-NVSS-API
- Expand sites
- Click on application you are updating, ex.
NVSS-FHIR-API-TEST
and on the right hand side under Manage Website select "Stop" to stop the API.
- In the remote desktop, open the file explorer and navigate to
D:/WebApps/
- Update the folders in the D drive so IIS will pickup the latest version
- Rename
NVSS-API-TEST
toNVSS-API-TEST-vx.x.x
wherevx.x.x
matches the version from step 12. - Rename the new version
NVSS-API-TEST-vx.x.x
toNVSS-API-TEST
- Optional, clean up any old API folder versions in
D:/WebApps/
that are no longer needed.
- Rename
- Update the folders in the D drive so IIS will pickup the latest version
- In the remote desktop, go to IIS and select "Start" to restart the API.
- Test the API is up and running
- Check the metadata endpoint, ex. for test it is
https://test.astv-nvss-api.cdc.gov/MA/metadata
, to confirm the API is up and running. - FOR DEV AND TEST ONLY, execute POST and GET test messages using either curl or Postmann to confirm the API is working as expected.
- Check the metadata endpoint, ex. for test it is
- RDP into the server, dev and test are on ASTV-NVSS-API.cdc.gov
- Open Internet Information Services
- Go to the Application pool and click advanced settings
- Click Identity and enter the new credentials in the Custom Identity field
To write logs to the log folder on the server:
- uncomment the logging line at the bottom of StartUp.cs
- uncomment the package in messaging.csproj to enable logging
- rebuild the release and deploy the code
Might get error for dotnet 6 extension when trying to access the server with the new version update. To resolve the issue, install the extension on the pbi server.
- Install .NET Core Hosting Bundle Installer to add dotnet support to IIS https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-6.0
- Configure the site in IIS https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-6.0&tabs=visual-studio