Deploying

sektorCMS is a normal ASP.NET Core app. It has to keep running as a program on a server, so it needs a server you can install software on, such as a small VPS.

Shared hosting plans (the kind with only a control panel and file upload) usually cannot run it, because there is no .NET runtime and no way to keep your own process alive.

On the server

  1. Install MariaDB and create the database and login (see Getting started).

  2. Publish the app. From your computer:

    dotnet publish -c Release -r linux-x64 --self-contained -o publish
    

    Copy the publish folder to the server, for example to /opt/cms.

  3. Give the app its settings as environment variables, in a file only the service can read (/etc/cms.env):

    ASPNETCORE_ENVIRONMENT=Production
    ConnectionStrings__DefaultConnection=Server=localhost;Database=cms;User=cms;Password=choose-a-long-password
    Api__Key=a-long-random-string
    Setup__SuperAdminEmail=you@example.com
    Storage__Path=/var/lib/cms/releases
    
  4. Create the tables. On your computer, with the same connection string, run dotnet ef database update. The tables are created the same way as in development.

  5. Run the app as a service, /etc/systemd/system/cms.service:

    [Unit]
    Description=sektorCMS
    After=network.target mariadb.service
    
    [Service]
    WorkingDirectory=/opt/cms
    ExecStart=/opt/cms/home.sektor9.dev --urls http://127.0.0.1:5000
    EnvironmentFile=/etc/cms.env
    Restart=always
    User=cms
    
    [Install]
    WantedBy=multi-user.target
    
    sudo systemctl enable --now cms
    

nginx in front

nginx takes the public traffic and hands it to the app on port 5000. Use a certificate from Let's Encrypt for https.

server {
    server_name example.com;
    client_max_body_size 1g;   # release uploads can be large

    location / {
        proxy_pass http://127.0.0.1:5000;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

The Upgrade lines are needed for Blazor's live connection.

Backups

Two things hold your data:

  • the database (mysqldump cms > cms.sql)
  • the release folder (Storage__Path)

Back both up together.

Updating

Publish again, copy the files over, run dotnet ef database update if there are new migrations, then sudo systemctl restart cms.

An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.