My experience with installing nopCommerce on Azure
Tags: nopcommerce, azure, azuresql, tutorial
Published: 2022-07-13 22:16:01

Since I have an affinity with C# and [.NET](https://dotnet.microsoft.com/en-us/learn/dotnet/what-is-dotnet), I wanted to try nopCommerce. nopCommerce is an open source e-commerce solution based on .NET technology. Before you set up nopCommerce on Azure, if you have a custom domain to use, make sure you have a SSL certificate for that domain. And then you create an Azure Web App service. You can follow this [tutorial](https://docs.microsoft.com/en-us/azure/app-service/quickstart-dotnetcore?tabs=net60&pivots=development-environment-azure-portal) to lay a ground foundation for ASP.NET app on Azure.

## Creation of Azure App Service Plan and SQL Database

At first, you might want to choose the B1 app service plan. Though it is a higher price, you just need it for set-up time. For experimental purpose development, you can scale down to F1 or D1 service plan after installation to use nopCommerce for almost free of charge. After creating the app plan, you can associate it with your [custom domain] (https://docs.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-custom-domain). You will still need B1 or higher app service plans to use custom domain and SSL. Otherwise, you can still use Azure's subdomain `{app_name}.azurewebsites.net` that comes with `HTTPS`. After that, you will need to create a SQL database service for the app. So there are service tiers that suit your app's demands. For my app, I just chose the purchasing model as `DTU` and the service tier as `basic tier`, which comes with a maximum of 5 [DTU] (https://docs.microsoft.com/en-us/azure/azure-sql/database/service-tiers-dtu) and 2GB of storage. That is about $5 per month, which is the lowest pricing for using [Azure SQL Database] (https://docs.microsoft.com/en-us/azure/azure-sql/database/single-database-create-quickstart?view=azuresql&tabs=azure-portal). After the creation, you should also configure the SQL server [firewall setting] (https://docs.microsoft.com/en-us/azure/azure-sql/database/firewall-create-server-level-portal-quickstart?view=azuresql) in the SQL Azure Portal under security and networking. You can set it as public access but only with selected networks with the IP address of the app and the IP addresses of development machines.

## Deployment of nopCommerce app

There are two ways to deploy the app on Azure. I don't find nopCommerce in the Azure app gallery as of now though. So I have tried FTP deployment and app publishing from Visual Studio. The best way is to publish it from Visual Studio. FTP deployment takes too long to transfer files to Azure. That may be due to the app service plan, which has basic hardware performance. But the file transfer is quicker with the Visual Studio deployment. I can either clone the app from nopCommerce's [GitHub site](https://github.com/nopSolutions/nopCommerce/) or download it from [releases] (https://github.com/nopSolutions/nopCommerce/releases) to do [FTP deployment] (https://docs.microsoft.com/en-us/azure/app-service/deploy-ftp?tabs=portal). To publish from Visual Studio, I need to download [publish profile] (https://docs.microsoft.com/en-us/visualstudio/azure/how-to-get-publish-profile-from-azure-app-service) from Azure App Service. In Visual Studio, when you publish the app, you can just [import] (https://docs.microsoft.com/en-us/visualstudio/deployment/deploying-applications-services-and-components-resources?view=vs-2022#import-profile) the publish profile that you downloaded from Azure app service.

## Setting up nopCommerce after Publishing or FTP.

Before you set up nopCommerce, make sure you start from your custom domain. If you don't have a custom domain, make sure HTTPS is turn on with Azure's subdomain in Azure App setting. Sometimes there may be connection time out during setup. So you can set `Connect Timeout = 120` or so in SQL connection string. If something goes wrong, I have to delete the database catalog in Azure SQL and files under `C:\home\site\wwwroot\` in web app because nopCommerce's Reinstall feature doesn't reset or delete the setting files to reinstall (I'll submit GitHub issue with that). The following PowerShell command is useful to remove files in the web app.
```
Remove-Item * -Recurse -Force
```
You can access PowerShell prompt for Azure web app via App Service's Advanced Tools under Development Tools and click the link `Go`. If you need to access the database stand-alone, you can use [Azure Data Studio] (https://docs.microsoft.com/en-us/sql/azure-data-studio/what-is-azure-data-studio) or Azure Portal's [SQL Query Editor](https://docs.microsoft.com/en-us/azure/azure-sql/database/connect-query-portal?view=azuresql#connect-to-the-query-editor). During my nopCommerce installation, I mixed up custom domain and Azure's subdomain. I shouldn't install under Azure's subdomain and access the site with custom domain. With that issue, the domain was inaccessible and I had to manually change the domain in setting table `dbo.Setting` in the database.

## Conclusion

It was a good experience using Azure App Service and Azure SQL Database. I learnt how to scale up or down web app and how to set up Azure SQL database. Azure App instances and SQL Database service tiers except `Basic` one can raise the cost of running services significantly. It could reach several hundred dollars in a month. Even when my website hasn't been launched or no one is accessing the site, there are automatic app activities or Azure's services running in the background. That could also raise the cost too high. I had tried to use SQL server on my Windows VM which is also hosted on Azure. It was not viable. Currently, I scale back the app to F1 free app service and basic Azure SQL database.