Guide to Setting Up nopCommerce on a Linux Server: A Step-by-Step Installation and Configuration

Guide to Setting Up nopCommerce on a Linux Server

Setting up a nopCommerce site on a Linux server might seem like a daunting task, but with the right steps, you can have your online store up and running smoothly in no time. In this guide, we’ll walk you through the five key phases of setting up your nopCommerce site on Linux, ensuring an efficient, well-optimized installation and configuration process:

  • Installing the .NET Runtime for ASP.NET Core
  • Organizing Your Directory Structure for Site Hosting & DB Naming
  • Hosting Process for nopCommerce
  • Extras: Linux Permissions and Common Commands

Part 1: Installing .NET on Linux

Step 1: Downloading the Microsoft Package

wget https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb

Purpose: Downloads the Microsoft package configuration file for the specified Ubuntu version.

Options:

  • https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb: URL for the Microsoft package configuration file, where $(lsb_release -rs) dynamically retrieves the version of Ubuntu.
  • -O packages-microsoft-prod.deb: Specifies the output file name for the downloaded package.

Example Explanation: This command downloads the Microsoft repository configuration file and saves it as packages-microsoft-prod.deb.

Step 2: Installing the Microsoft Package

sudo dpkg -i packages-microsoft-prod.deb

Purpose: Installs the downloaded Microsoft package to configure the Microsoft repository on the system.

Options:

  • sudo dpkg -i packages-microsoft-prod.deb: Uses dpkg to install the downloaded .deb package.

Step 3: Updating the Package List

sudo apt update -y

Purpose: Updates the local package list to include the Microsoft repository.

Example Explanation: Runs the apt update command to update the package index and sync it with the added Microsoft repository.

Step 4: Installing Required Packages

sudo apt install apt-transport-https -y

Purpose: Installs the apt-transport-https package, enabling apt to fetch packages over HTTPS.

Step 5: Installing dotnet-runtime-8.0

sudo apt-get install -y dotnet-runtime-8.0

Purpose: Installs the .NET Runtime 8.0 on the system.

Step 6: Installing aspnetcore-runtime-8.0

sudo apt install -y aspnetcore-runtime-8.0

Purpose: Installs the ASP.NET Core Runtime 8.0, which is required for running ASP.NET Core applications.

Important Notes

  • Permissions: Ensure you have superuser privileges to run commands with sudo.
  • Dependencies: The apt-transport-https package is required for secure package fetching.
  • Version: This guide installs dotnet-runtime version 8.0, but you can modify the version number as needed for different versions of .NET.

Part 2: Site Hosting & DB Naming

Root Directory Structure

/var/www: Main directory for all website data.

/var/www/NopSites: Dedicated directory for all nopCommerce installations.

Site-Specific Directory Structure

Each hosted site will follow this structure:

/var/www/NopSites/<SiteType>/<BaseNopVersion>/<SiteType>_<ServiceName>

SiteType: Environment type for the nopCommerce site, such as Demo, Test, AppSite, Theme, or Client.

BaseNopVersion: Major version of nopCommerce (e.g., 470 for version 4.70.x).

ServiceName: Custom name provided during setup.

Example

Suppose you set:

  • Site Type: Client
  • Base nopCommerce Version: 470
  • Service Name: NopStore

Your directory structure will appear as:

/var/www/NopSites/Test/470/Client_NopStore

Database Structure

The database name structure will follow this format:

<SiteType>_<ServiceName>_<BaseNopVersion>

Example: If you have:

  • Site Type: Test
  • Service Name: MyStore
  • Base Version: 470

The resulting database name would be:

Test_MyStore_470

Important Notes

  • Directory Naming: Ensure the directory names follow the correct format for consistent organization.
  • Database Naming: Maintain the same naming convention for databases to easily associate them with their respective sites.

Part 3: Hosting Process for nopCommerce

Step 1: Create the Hosting Path

Run the following command to create the path:

cd /var/www/NopSites/<SiteType>/<BaseNopVersion>/<SiteType>_<ServiceName>

Rule to Create Path:

  • SiteType: Environment type for the nopCommerce site (e.g., Demo, Test, AppSite, Theme, Client).
  • BaseNopVersion: Major version of nopCommerce (e.g., 470 for version 4.70.x).
  • ServiceName: Custom name provided during setup.

Example: /var/www/NopSites/Test/470/Client_NopStore

In this document, we will refer to this path as $nopHostingDir.

Step 2: Switch to the Directory

Once the path is created, switch to it using the following command:

cd /var/www/NopSites/Test/470/Client_NopStore

Step 3: Download Latest nopCommerce Version

Use the following command to download the latest version of nopCommerce from GitHub:

sudo wget https://github.com/nopSolutions/nopCommerce/releases/download/release-${nopVersion}/nopCommerce_${nopVersion}_NoSource_linux_x64.zip

Note: Replace ${nopVersion} with the specific version you want to host.

Step 4: Extract Files from the ZIP Archive

Extract the files using the following command:

sudo unzip nopCommerce_${nopVersion}_NoSource_linux_x64.zip

Step 5: Delete the Original ZIP Archive

To save space, delete the original zip archive:

rm nopCommerce_${nopVersion}_NoSource_linux_x64.zip

Step 6: Create Subdirectories Within $nopHostingDir

To create all required subdirectories within $nopHostingDir, run the following command:

mkdir -p "$nopHostingDir" \
               "$nopHostingDir/App_Data" \
               "$nopHostingDir/wwwroot" \
               "$nopHostingDir/wwwroot/images" \
               "$nopHostingDir/wwwroot/images/thumbs" \
               "$nopHostingDir/wwwroot/js" \
               "$nopHostingDir/wwwroot/uploads"

Step 7: Set Permissions and Ownership for nopCommerce Directories

Apply correct permissions and ownership for the web server to interact with the files:

sudo chmod -R 755 "$nopHostingDir" && sudo chown -R www-data:www-data "$nopHostingDir"

Step 8: Create a New Systemd Service File

This step allows you to manage nopCommerce as a service (starting and stopping like other services). Open the service file using the following command:

sudo nano /etc/systemd/system/nop_${selectedSiteType}_${dirNServiceName}_${baseNopVersion}.service

In the file, paste the following content:


      # ************************************* #
      
      [Unit]
      Description=NopCommerce $nopVersion application type of $selectedSiteType for $dirNServiceName
      
      [Service]
      WorkingDirectory=$nopHostingDir
      ExecStart=/usr/bin/dotnet "$nopHostingDir/Nop.Web.dll" --urls=http://0.0.0.0:$port
      Restart=always
      
      # Auto restart nopCommerce in 10 seconds if .NET crashes
      RestartSec=10
      KillSignal=SIGINT
      SyslogIdentifier=nopcommerce
      User=www-data
      Environment=ASPNETCORE_ENVIRONMENT=Production
      Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
      
      [Install]
      WantedBy=multi-user.target
      EOF
      # ************************************* #

Replace the Placeholders:

  • $nopVersion: Replace with the base nopCommerce version (e.g., 4.70).
  • $selectedSiteType: Replace with the site type (e.g., Test, Demo, etc.).
  • $dirNServiceName: Replace with the name of the service or site.
  • $nopHostingDir: Replace with the full directory path where nopCommerce is located.

Example: nop_Client_NopStore_470.service

Step 9: Reload Systemd and Start the Service

Reload the systemd service files and start the service with the following commands:


      sudo systemctl daemon-reload
      sudo systemctl enable $serviceName
      sudo systemctl start $serviceName

Replace the Placeholder:

  • $serviceName: Replace with the service file name you created earlier (e.g., nop_Client_NopStore_470.service).

Extras: Linux Permissions and Common Commands

Permission Commands

chmod - Change file or directory permissions.

chmod [options] permissions file

Example:

sudo chmod 755 /path/to/dir

Explanation:

  • 7 (owner): read (4) + write (2) + execute (1) = 7
  • 5 (group): read (4) + execute (1) = 5
  • 5 (others): read (4) + execute (1) = 5

Permissions:

  • r (read): 4
  • w (write): 2
  • x (execute): 1

chown - Change the ownership of files or directories.

chown [owner][:group] file

Example:

sudo chown user:group /path/to/file

Common Linux Commands

cd - Change directory.

cd /path/to/dir

mkdir - Create a new directory.

mkdir new_folder

nano - Open a text editor to edit files.

nano filename.txt

systemctl - Manage system services.

sudo systemctl restart nginx

journalctl - View system logs.

journalctl -u nginx

ls - List files in a directory.

ls /path/to/dir

ls -l - List files with detailed permissions and attributes.

ls -l /path/to/dir

htop - Interactive process viewer.

htop

cat - Display the content of a file.

cat filename.txt

cp - Copy files and directories.

cp source_file destination_file

Force copy (overwrite):

cp -f source_file destination_file

unzip - Unzip a .zip file.

unzip file.zip

unrar - Extract .rar files.

unrar x file.rar

wget - Download files from the internet.

wget https://example.com/file.tar.gz

Overview of sudo and apt (for Installing Software)

sudo

Purpose: Grants temporary superuser (root) privileges to run commands.

sudo [command]

Example:

sudo systemctl restart apache2

This command runs systemctl restart apache2 with root privileges, allowing access to files and commands restricted to the root user.

apt (Advanced Package Tool)

Purpose: Manages software packages in Debian-based systems (like Ubuntu).

Common Commands:

    • apt install: Installs packages.
sudo apt install [package_name]
    • apt update: Updates the list of available packages and versions (doesn’t install or upgrade any packages).
sudo apt update
    • apt upgrade: Installs the latest versions of all packages currently installed on the system.
sudo apt upgrade

Linux Command Cheat Sheet:

    • For other useful commands not covered here, please checkout the command cheat sheet.

Full script to host linux on nopCommerce:

card icon
Book a Meeting