Hosting on Linux
# help-with-umbraco
n
Hi there 👋, I'm trying to host my Umbraco 13 CMS on my debian server. I installed .net8.0, umbraco (along with its templates), created a .service file so the CMS can run as a service and ran
dotnet publish --os linux
. Before running the service i started the web with dotnet build and synchornized some files so it installation would match my lcoal dev. That said, with
dotnet build
Umbraco worked perfectly fine - frontend, backend, file handling all went well. But with the service running the backend doesn't seem to work anymore. The browser is trying to fetch files like https://mydomain.com/umbraco/login/login.iife.js but the kestrel server just returns a 404. Nothing obvious is logged. I didn't find anything similiar yet - has anyone an idea what might be the cause / solution to the cause? This is my .service file:
Copy code
[Unit]
Description=Noels umbraco CMS web
Wants=network.target
After=network.target

[Service]
WorkingDirectory=/var/www/html/myWebProject/
ExecStart=/usr/bin/dotnet /var/www/html/myWebProject/bin/Release/net8.0/linux-x64/publish/myWebProject.dll
SyslogIdentifier=NCSumbraco
User=root
Restart=always
RestartSec=5
KillSignal=SIGINT
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
Environment=ASPNETCORE_URLS=https://*:44332

[Install]
WantedBy=multi-user.target
Thanks!
k
ASPNETCORE_ENVIRONMENT=Production
means only
appSettings.json
and
appsettings.Production.json
would be read. Nothing important in
appSettings.Development.json
by mistake?
If you attempt to browse a known static file (a file in
wwwroot
) do you still get a 404?
n
No, I don't get a 404 when browsing for a static (e.g.
/css/layout.css
) file in
wwwroot
r
When you do a
dotnet publish
the output directory (in this case
bin/Release/net8.0/linux-x64/publish
) will contain everything you need to run the app, so this is the only directory you need to deploy to your server. Then in the systemd service the working directory should be updated to be the publish folder and you should be able to simplify
ExecStart
to
dotnet myWebProject.dll
.
n
if I change the service file as you suggested the service will crash with an exception after ca. 2s.
Copy code
[Service]
WorkingDirectory=/var/www/html/myWebProject/bin/Release/net8.0/linux-x64/publish
ExecStart=dotnet myWebProject.dll
Should my web point directly to the
publish
dir instead of
myWebProject
? This is the "stack trace" after it crashing (called via
journalctl -u umbraco
)
Copy code
Started umbraco.service - umbraco CMS web.
Apr 23 15:24:54 debian umbraco[246178]: Unhandled exception. System.IO.DirectoryNotFoundException: /var/www/html/myWebProject/bin/Release/net8.0/linux-x64/publish/wwwroot/media/
Apr 23 15:24:54 debian umbraco[246178]:    at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
Apr 23 15:24:54 debian umbraco[246178]:    at Umbraco.Cms.Core.IO.PhysicalFileSystem.Create()
Apr 23 15:24:54 debian umbraco[246178]:    at Umbraco.Extensions.FileSystemExtensions.TryCreateFileProvider(IFileSystem fileSystem, IFileProvider& fileProvider)
Apr 23 15:24:54 debian umbraco[246178]:    at Umbraco.Cms.Core.IO.ShadowWrapper.Create()
Apr 23 15:24:54 debian umbraco[246178]:    at Umbraco.Extensions.FileSystemExtensions.TryCreateFileProvider(IFileSystem fileSystem, IFileProvider& fileProvider)
Apr 23 15:24:54 debian umbraco[246178]:    at Umbraco.Extensions.ApplicationBuilderExtensions.UseUmbracoMediaFileProvider(IApplicationBuilder app)
Apr 23 15:24:54 debian umbraco[246178]:    at Umbraco.Cms.Web.Common.ApplicationBuilder.UmbracoApplicationBuilder.RegisterDefaultRequiredMiddleware()
Apr 23 15:24:54 debian umbraco[246178]:    at Umbraco.Cms.Web.Common.ApplicationBuilder.UmbracoApplicationBuilder.WithMiddleware(Action`1 configureUmbracoMiddleware)
Apr 23 15:24:54 debian umbraco[246178]:    at Program.<Main>$(String[] args) in /var/www/html/myWebProject/Program.cs:line 15
Apr 23 15:24:54 debian umbraco[246178]:    at Program.<Main>(String[] args)
Had to remove [systemd] trace because of character limit.
r
Yeah, the workingdirectory should be the publish folder. From the error, it looks like the
publish/wwwroot/media
directory is missing, what happens if you create it manually?
n
After creating the dir manually I don't get an exception anymore. However Umbraco isn't able to boot correctly - meaning I get an error screen stating
Boot Failed Umbraco failed to boot, if you are the owner of the website please see the log file for more details.
but neither the Umbraco nor the service log contain any helpful information (at least for me). I'll adjust the log settings tomorrow and follow up if i found something useful. https://cdn.discordapp.com/attachments/1231945368112201748/1232449656882073690/umbracoLog_notVerbose.json?ex=66297fb0&is=66282e30&hm=dd18f125d8c157905afd77f2890ff378ebe71712535965433b8c873b8ad2836c&
h
Also try clearing out all files and republishing, I've had these issues when there have been old DLLs still lurking around.
d
I've had a similar sequence of issues before on a Windows server, with the final error ("Umbraco failed to boot…") caused by an incorrect database connection setting, so worth double checking that.
n
That seems to be one problem (hopefully the only one)
Copy code
JSON
{
    "@t": "2024-04-24T19:27:39.6112680Z",
    "@mt": "Configured database is reporting as not being available.",
    "@l": "Warning",
    "@x": "Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 14: 'unable to open database file'.\n   at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)\n   at Microsoft.Data.Sqlite.SqliteConnectionInternal..ctor(SqliteConnectionStringBuilder connectionOptions, SqliteConnectionPool pool)\n   at Microsoft.Data.Sqlite.SqliteConnectionPool.GetConnection()\n   at Microsoft.Data.Sqlite.SqliteConnectionFactory.GetConnection(SqliteConnection outerConnection)\n   at Microsoft.Data.Sqlite.SqliteConnection.Open()\n   at Umbraco.Extensions.DbConnectionExtensions.IsAvailable(IDbConnection connection)",
    "SourceContext": "object",
    "ProcessId": 268939,
    "ProcessName": "dotnet",
    "ThreadId": 1,
    "ApplicationId": "50200c2e81ad54bc53fb151e21469ccb6cb77a58",
    "MachineName": "debian",
    "Log4NetLevel": "WARN "
}
{
    "@t": "2024-04-24T19:27:39.6176903Z",
    "@mt": "Could not immediately connect to database, trying again.",
    "@l": "Debug",
    "SourceContext": "Umbraco.Cms.Infrastructure.Runtime.RuntimeState",
    "ProcessId": 268939,
    "ProcessName": "dotnet",
    "ThreadId": 1,
    "ApplicationId": "50200c2e81ad54bc53fb151e21469ccb6cb77a58",
    "MachineName": "debian",
    "Log4NetLevel": "DEBUG"
}
I'm not sure why but the sqlite database file was missing in the
publish/umbraco/Data
dir. After a quick minor update and copying the sqlite file to the dir it seems to work just fine - at least for now ^^ Thank you guys!
s
Careful on your next deploy not to delete it! I've done that 🤦 I am paranoid now, each deploy starts with a backup of database and media files (though that's not great once you start having a lot of media files). I'm not super familiar with Linux so I haven't found an easier way to avoid accidentally deleting important data yet. You usually wouldn't publish the database each time, unless you do 0 editing on your live site. Personally, I use uSync to get changes in (for example) document types from my development to my live site. Good to look into and experiment with.
k
Not sure if relevant here but msdeploy and Azure have options to "delete all extra files from the target directory" when deploying which is usually a good thing since old/obsolete assemblies will break the application, and an option to "exclude files from App_Data" since historically these were "dynamic content". **But App_Data isn't where the Umbraco sqlite usually resides **so those options will usually delete the sqlite database. Perhaps relocating the sqlite database (I believe it can be anywhere? Even above the publish folder) would reduce the removal risk. I believe my personal accidentally-deleted-the-sqlite-unrecoverably count is 3. 🙂
s
Sure thing! I am deploying manually so I'm doing the backup first. As usual, we advise not to use SQLite for live sites, which removes this risk. But I wonder what happens with the media folder when extra files get deleted? or is it only because
App_Data
is special?
240 Views