Run Optimizely CMS 12 and Commerce locally: 7 first-day errors
Seven things that break when you clone a hosted Optimizely site onto your own machine, each with its symptom, its cause and its fix, plus a checklist to follow on day one.
I joined a project that ran on Optimizely CMS 12, Optimizely’s content management system (CMS), with Customized Commerce, hosted on the Optimizely Digital Experience Platform (DXP), which is Optimizely’s managed Azure hosting. The team handed me a repository, two database files and a README. The site did not run on the first try, or the second. Each failure had a different cause, and most of the error messages pointed somewhere else.
This post is the list I wish I had been given. It is for a developer who is new to Optimizely, or who comes from Sitecore and expects an installer.
What a local Optimizely site is made of
There is no installer for the CMS. The CMS and Commerce are NuGet packages inside your app. Running the site locally means starting that app and giving it everything it expects to find.
- Two SQL Server databases. The CMS database holds the content tree: pages, blocks, media records, users and roles. The Commerce database holds the catalog, prices and orders. They have separate connection strings,
EPiServerDBandEcfSqlConnection. - Optimizely Find. A hosted search service. The app talks to it at startup, so it must be reachable.
- Media blob storage. The image and document files themselves. On DXP these sit in Azure Blob storage, not in the database.
- An identity provider. Many projects sign people in through an external identity provider over OpenID Connect (OIDC), a standard sign-in protocol, which gives them single sign-on (SSO). Roles may come from there.
- A front-end build. Here it was Vite for JavaScript and gulp for CSS, run alongside the app.
The team’s databases came as two .bacpac files. A bacpac is a portable database package: schema and data in one file. It is not a backup in the SQL Server sense. You import it into a fresh database.
Here is where each part bit me, in order.
1. The SDK that your newer .NET does not satisfy
Symptom. I had .NET 9 and 10 installed and expected them to build the project. Before the first build I checked which software development kit (SDK) the repository asks for. Neither of mine qualified.
Cause. The repository pinned the SDK in global.json:
{ "sdk": { "version": "8.0.418", "rollForward": "latestFeature", "allowPrerelease": false }}latestFeature lets .NET pick a later patch or feature band within the same major and minor version. So 8.0.418 accepts 8.0.422 or an 8.0.5xx SDK, but never 9 or 10. A machine without an 8.0 SDK at 8.0.418 or later cannot build the project.
Fix. Install the .NET 8 SDK next to the others. Newer SDKs stay installed. Check the list:
dotnet --list-sdksI installed 8.0.422, which satisfied the 8.0.418 pin.
2. Restoring two bacpacs without the interactive script
The repository had a PowerShell script that downloads and restores the databases, but it asks you to pick each bacpac at a prompt. I wanted to run it unattended, so I did what it does by hand. It needs SqlPackage, Microsoft’s command-line tool for bacpac files, and a local SQL Server where your Windows account can create databases.
First install SqlPackage as a .NET global tool:
dotnet tool install -g microsoft.sqlpackageThen import each file into a new database. This creates the database, builds every table and index, loads the rows and turns the indexes back on:
$cs = "Data Source=.;Database=Site_cms_local;Integrated Security=True;TrustServerCertificate=true"sqlpackage /Action:Import /SourceFile:"site.cms.bacpac" /TargetConnectionString:"$cs"Run it again with a second database name and the Commerce file. On my laptop the CMS import took 3 minutes 55 seconds, and the smaller Commerce one under five minutes. A bacpac rebuilds the whole database, so it is not a quick restore.
The repository also shipped two small SQL scripts to run afterwards. One rewrites the site’s URLs to localhost and turns off scheduled jobs. The other patches a quirk in the Commerce catalog. Run them with sqlcmd against each database.
Last, point the app at the databases. I put this in a machine-specific settings file, which I explain in trap 3:
{ "ConnectionStrings": { "EPiServerDB": "Data Source=.;Database=Site_cms_local;Integrated Security=True;TrustServerCertificate=true;MultipleActiveResultSets=True", "EcfSqlConnection": "Data Source=.;Database=Site_commerce_local;Integrated Security=True;TrustServerCertificate=true;MultipleActiveResultSets=True" }}3. The Find index that expires after 30 days
Symptom. The app had started fine a month earlier. Then dotnet run crashed on startup:
Unhandled exception. EPiServer.Framework.Initialization.InitializationException:Initialize action failed for Initialize on class ...NestedConventionsInitialization ---> EPiServer.Find.ServiceException: Response status code does not indicate success: 401 (Unauthorized).Cause. I had made a free Find demo index on 13 July (the portal labels it “Developer Service”), and the failure came on 12 August, exactly 30 days later. Optimizely’s own pages say a demo index is removed after 30 days, and a support article lists no search results, 401 errors and failed indexing as the symptoms.
My first move was to change the index name. The 401 stayed. A 401 means the service rejected the key, and the key is the last segment of the service URL, not the index name. A new index needs a new URL as well.
Fix. Create a new demo index in the Find portal, then update both values from its private URL. Put them in a settings file named after your machine. This project’s startup code loads appsettings.json, then appsettings.{Environment}.json, then appsettings.{MachineName}.json, then environment variables, and the later ones win. The machine file is the project’s own addition, not an ASP.NET Core default.
{ "EPiServer": { "Find": { "DefaultIndex": "your-username_your-index", "ServiceUrl": "https://service-demo.find.episerver.net/<private key>" } }}The index is empty until you run an indexing job, so search returns nothing at first. Expect a different startup error next, too. After the Find error went away, mine stopped on a settings section for the digital asset manager (DAM) that no file in the repo defined, then on a similar gap in the translation settings. Startup failures arrive one at a time.
4. The npm 401 that tells you to log in
Symptom. npm install failed:
npm error code E401npm error Incorrect or missing password.npm error If you were trying to login, change your password, create an authentication token or enable two-factor authentication then that means you likely typed your password in incorrectly.npm error Please try again, or recover your password at:npm error https://www.npmjs.com/forgotnpm errornpm error If you were doing some other operation then your saved credentials are probably out of date.npm error To correct this please try logging in again with:npm error npm loginI made a personal npm account and ran npm login. Same error.
Cause. The hint is printed on every 401, whichever registry sent it. The log showed the real source: a request to npm.fontawesome.com, not to npmjs. The repository’s .npmrc sends two package scopes to the Font Awesome Pro registry:
registry=https://registry.npmjs.org/@fortawesome:registry=https://npm.fontawesome.com/@awesome.me:registry=https://npm.fontawesome.com/npm login only signs you in to npmjs. Font Awesome uses a static token, and the repo deliberately keeps it out of git. My user-level ~/.npmrc held a placeholder I had added earlier, so npm sent that literal text as the credential.
Fix. Get a Pro token from the team and put one line in the user-level file in your home folder. The repo’s file is tracked, so a token there would be committed:
//npm.fontawesome.com/:_authToken=<your Font Awesome Pro token>Then install from the folder that holds package.json. The project used --legacy-peer-deps:
npm i --legacy-peer-depsnpm config get refuses to print this key (“protected”), so open the file and check the line yourself. I did not wait for the token. To get the app running I removed the two Font Awesome packages locally, which gave a clean install and blank icons. That is a local workaround to undo later, not a fix.
5. The empty page that is really a 30 second wait
Symptom. The app was listening on port 3002, but https://localhost:3002 showed an empty response in the browser.
Cause. Two things at once. The ASP.NET Core development certificate was not trusted; the log said so. And the first request is slow while Optimizely starts its services. Fetching the home page with curl -k, which skips the certificate check, took 32 seconds and returned the full page.
Fix. Trust the certificate once, click Yes on the Windows prompt, then wait on the first load:
dotnet dev-certs https --trustThe first dotnet run also builds dozens of projects. Mine took about three minutes before the app started.
6. Every /en page goes to SSO, and the images look broken
Symptom. The home page at / loaded. Every page under /en/ redirected to the identity provider’s sign-in page, and so did most images.
Cause. Not content permissions. The content root granted Everyone read access and the start page inherited it. One line in Startup.cs required a signed-in user for the whole path. UsePathAuthorization is a small middleware the project carries in its own code, not part of Optimizely or ASP.NET Core:
app.UsePathAuthorization(options => { options.AuthorizePath("/en"); });Images under /en/... hit the same rule, while files outside it (/siteassets) returned 200.
A second cause sits behind the redirect. The bacpac holds media records, not media files. My App_Data/blobs folder, where a local site keeps them, did not exist, so uploaded images would have nothing to serve. I did not test that once the redirect was gone.
Fix. For the redirect I skipped the rule in Development only. This is a local workaround. Do not commit it:
app.UsePathAuthorization(options => { options.AuthorizePath("/en"); });app.UsePathAuthorization(options =>{ if (!string.Equals(env.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase)) { options.AuthorizePath("/en"); }});Start the app with ASPNETCORE_ENVIRONMENT set to Development, or the rule stays on. This project’s default launch profile sets it; dotnet run --no-launch-profile does not. For the blobs, ask the team how they fill that folder; the usual options differ by project. Images served from the DAM may also need a virtual private network (VPN).
A short note on /admui
After signing in at /admui, where this project serves the editing interface, the browser showed a 403. That is progress: the identity provider accepted me, but my user carried no CMS roles. A diagnostic page listed only the roles Authenticated and Everyone.
The roles must come from the identity provider, so the supported fix is to ask for your account to be mapped to an editor group. A dev-only role grant, added as middleware, also worked for me. A claims transformation I tried first never ran, and I did not confirm why. I wrote up the full hunt as why the edit UI returns 403 after an OpenID Connect sign-in.
Once you are in the editor, a Select Content dialog that spins forever has a different cause: a content area limited to an interface that does not inherit IContentData. And if an API response you add comes back as only {"errors":[]}, see how a DataContract attribute on a base class drops properties in Newtonsoft.Json.
How to check it worked
dotnet --list-sdksshows an 8.0 entry.- Both databases exist:
sqlcmd -S . -E -Q "SELECT name FROM sys.databases". - The
dotnet runlog shows noInitializationException, andcurl -k https://localhost:3002/returns 200 after the first slow load. https://localhost:3002/en/renders without leaving localhost.
The first-day checklist
- Install the SDK named in
global.json. Confirm withdotnet --list-sdks. - Install SQL Server, make sure your Windows account can create databases, and install SqlPackage.
- Import the CMS and Commerce bacpacs into two new databases. Run the repo’s local-fix SQL on each.
- Create
appsettings.<MACHINE>.jsonand add both connection strings. - Create a Find demo index. Put
DefaultIndexand the privateServiceUrlin that same file. Note the date: it ends in 30 days. - Put the Font Awesome token in
~/.npmrc, not the repo’s. Runnpm i --legacy-peer-deps. - Start the front-end watchers (
npm run dev:js,npm run dev:css) and setASPNETCORE_ENVIRONMENT=Development. - Run
dotnet dev-certs https --trust, thendotnet run. Allow a few minutes the first time. - Wait about 30 seconds on the first request. Use
https. - Ask about media blobs, VPN-only services and editor roles on day one, not day five.
Takeaways
- A local Optimizely site is an ASP.NET Core app plus two databases, a search index, blobs and an identity provider. Know which of those you were given.
global.jsonwithlatestFeaturenever reaches a newer major SDK.- A Find 401 is about the key in the service URL. Change the URL as well as the name.
- npm’s “try npm login” line appears on every 401. Read which host answered.
- A bacpac restores the data, not the files that the data describes.
- Keep every local workaround in untracked files, or marked clearly local, and say so before it is committed.