How to Self-Host Medusa with Localtonet
Set up and verify a local Medusa commerce application using its official guide, then provide remote HTTP access with Localtonet.
In this article 10 sections
Run Medusa locally and give authorized collaborators temporary remote access
This guide covers a Medusa development environment with PostgreSQL, local Admin verification, and temporary HTTPS access through Localtonet. It explains how to identify the generated backend directory, configure the assigned public origin, and test authentication before sharing access. Installing a storefront and deploying a production commerce system are outside the demonstrated scope. The production section is a planning checklist, not a deployment recipe.
📋 What's in this guide
Understand what you are publishing
Medusa is an open-source commerce platform and framework for building customized commerce applications. Its core commerce modules are open source; separately identified Enterprise Edition materials require a commercial agreement. Medusa can support direct-to-consumer stores, business-to-business systems, marketplaces, distributor platforms, and other applications built around reusable commerce capabilities.
A standard project is not a single customer-facing website. The Medusa application includes the server and Admin dashboard. A storefront is a separate application that connects to the server. PostgreSQL stores application data. Production architecture also includes Redis and typically separates request handling from background processing.
Forwarding the Medusa HTTP listener exposes every route served by that listener, including applicable /app, /admin, /auth, /store, and custom routes. Sharing a URL ending in /app does not restrict other paths. Route restrictions require separately configured and verified routing controls.
Choose a host and verify prerequisites
The shell examples below target Ubuntu 24.04 LTS with Bash, with Node.js, npm, and PostgreSQL already installed by the host administrator. Installing those runtimes from an empty operating system is outside this guide's scope. You need sudo access for the database administrator session, a private development database, and permission to publish the development service.
The supplied Medusa documentation identifies v2.22.7. The accompanying generator walkthrough was last updated October 28, 2026 and reports Node.js 22.23.4 or later for its generated project. That is the dated evidence baseline, not an execution-test date. No installation was executed for this revision, and no tested generator/backend dependency matrix is claimed. The available excerpts do not establish the current generator version or the selected release's minimum PostgreSQL version. Verify those requirements before provisioning or installing; do not infer them from the older v2.19 release.
Prefer a currently maintained Node.js LTS line that satisfies the actual generated packages. Historical compatibility is not a maintenance recommendation. In particular, the Medusa v2.19.0 release notes specified Node.js ^20.19.0, ^22.12.0, or a greater LTS version. Those older requirements do not certify a current generator installation.
That historical release also upgraded the Admin to Vite 7.3.6 and React Router 7.18.2, with browser minimums of Chrome 107, Edge 107, Firefox 104, and Safari 16. If maintaining that release, review its Vite configuration and React Router breaking changes. For a new installation, use a maintained browser and the requirements of the release actually installed.
Check the installed tools and database service
cat /etc/os-release
node --version
npm --version
psql --version
sudo systemctl start postgresql
sudo systemctl status postgresql --no-pager
pg_isready -h 127.0.0.1 -p 5432
These commands assume a PostgreSQL installation managed by Ubuntu's systemd service. A container or managed database requires its own startup procedure. psql --version identifies the client, not the running server. Even pg_isready only establishes that a server is responding; the application-role connection test below is the important final check.
Supplement these checks with the Medusa installation requirements, official Node.js installation options, and PostgreSQL's Ubuntu installation instructions. Until the PostgreSQL version requirement is confirmed for your chosen Medusa release, treat compatibility as an unresolved prerequisite.
Create an isolated development database
Enter the administrator session on the selected Ubuntu host:
sudo -u postgres psql
Inside psql, create a dedicated role and set its password interactively. This avoids placing a reusable password in the article or a SQL command saved in history.
CREATE ROLE medusa_user LOGIN;
\password medusa_user
CREATE DATABASE medusa_db OWNER medusa_user;
\q
Now connect as the application role, through the same TCP address the application will use:
psql -h 127.0.0.1 -p 5432 -U medusa_user -d medusa_db -W \
-c 'SELECT current_user, current_database(), version();'
Enter the password when prompted. Confirm the result identifies medusa_user, medusa_db, and the expected server version. Do not continue on an authentication or connection error. A database owner is appropriate for initial migrations in this isolated development database; it does not need PostgreSQL superuser privileges.
The connection URL has the following shape. Percent-encode password characters that have special meaning in a URL. Keep the completed value private:
postgres://medusa_user:ENCODED_PASSWORD@127.0.0.1:5432/medusa_db
For a managed database, use the provider's required TLS settings. Where the provider distinguishes pooled and direct connections, use a connection suitable for setup and migrations. Do not expose PostgreSQL publicly to fix an application connectivity problem.
Create Medusa and inspect what the generator produced
The documented generator workflow installs dependencies, configures the database connection, runs initial migrations, seeds initial data, and starts the development server. A moving @latest command is not a version-pinned tutorial. Resolve and record the generator version first, then inspect the generated application's versions independently.
GENERATOR_VERSION="$(npm view create-medusa-app version)"
printf 'Generator version: %s\n' "$GENERATOR_VERSION"
npm view "create-medusa-app@$GENERATOR_VERSION" engines --json
Check the reported engine requirements against your runtime before continuing. Generator metadata alone does not prove that every dependency or generated template supports that runtime. If requirements differ from the dated evidence above, stop and resolve them rather than ignoring engine warnings.
Run the generator without saving the database URL in shell history
read -r -s -p "Private PostgreSQL URL: " MEDUSA_DB_URL
printf '\n'
npx "create-medusa-app@$GENERATOR_VERSION" --db-url "$MEDUSA_DB_URL"
unset MEDUSA_DB_URL
Choose a project name such as my-medusa-store and decline the optional Next.js Starter Storefront. This guide deliberately demonstrates only the backend and Admin. The expanded database URL can still appear in process arguments while the generator runs, so use a trusted development host without untrusted local users.
Allow initialization to finish. Review migration and seed output. If initialization fails, repair the specific problem before rerunning anything against the database. Do not repeatedly seed an existing environment or mark failed migrations as complete.
Find the backend instead of assuming the project root
The current supplied walkthrough places the backend in my-medusa-store/apps/backend. Other generated layouts can differ. In a second terminal, inspect the actual project:
cd my-medusa-store
find . -name node_modules -prune -o -name medusa-config.ts -print
For a result of ./apps/backend/medusa-config.ts, enter apps/backend. For ./medusa-config.ts, remain at the project root. If several files appear, identify the backend package before proceeding.
# Use this only when the result above is ./apps/backend/medusa-config.ts
cd apps/backend
pwd
ls -la medusa-config.ts .env package.json
npm pkg get scripts engines
npm ls @medusajs/medusa @medusajs/framework @medusajs/cli --depth=0
The directory containing the backend's medusa-config.ts is the working directory for subsequent backend commands. Its .env contains private runtime configuration. Do not print that file into shared logs. Inspect package.json to confirm the development script runs Medusa, rather than assuming a repository-root script does so.
Save the generator version, Node.js and npm versions, PostgreSQL server version, resolved Medusa package versions, and your actual verification date in a private project record. Preserve the generated lockfile and identify its workspace root. Pinning the generator does not pin the generated dependencies; the lockfile and installed package report establish what you actually obtained.
Create the first Admin account
Complete the registration form if the generator opens it. If the browser does not open, use the Medusa user command from the backend directory. The following Bash example prompts for unique credentials rather than publishing a password:
read -r -p "Admin email: " ADMIN_EMAIL
read -r -s -p "Unique Admin password: " ADMIN_PASSWORD
printf '\n'
npx medusa user -e "$ADMIN_EMAIL" -p "$ADMIN_PASSWORD"
unset ADMIN_EMAIL ADMIN_PASSWORD
As with the database setup command, expanded arguments may be visible to local process inspection. Run this only on a trusted host, do not record the terminal session, and retain the password in your password manager. Use this fallback to create the first account, not as an assumed password-reset procedure.
Start and verify the local application
If the generator's server is still running, leave it running. Otherwise, after confirming that the backend package defines the expected dev script, start it:
npm run dev
In a separate terminal, check the listener reported by Medusa:
curl -I http://localhost:9000/app
Open http://localhost:9000/app, sign in, and load a protected Admin page such as the product list. A redirect or successful HTML response alone does not verify authentication or API access. Resolve database, script-loading, or login failures before making the listener public.
Create the Localtonet HTTP tunnel
Our client establishes an outbound connection to a relay server. The HTTP tunnel provides a public HTTPS address without inbound router port forwarding, firewall changes, VPN setup, or a public IP address. Standard HTTP tunneling is not a VPN.
Follow the current Localtonet HTTP tunnel guide for the client package and dashboard instructions. That existing documentation address is retained here; its live redirect behavior has not been checked for this revision. Exact installer commands and a numbered current HTTP documentation extract were not supplied, so the sequence below is a configuration checklist, not a claim that the documentation has this exact number of steps.
Install and run the client
Use our client for the host operating system. Run it on the Medusa host for the simplest target configuration. Authenticate it with its device-specific token using the current client instructions, and confirm that the intended device is connected in our dashboard. Keep that token private.
Open the HTTP tunnel page and select Process Type
Choose an HTTP tunnel and select Random Sub Domain, Custom Sub Domain, or Custom Domain as available. A generated subdomain avoids custom-domain DNS setup for this temporary demonstration. Consult current documentation before configuring custom-domain DNS.
Select the device token and relay server
Select the AuthToken associated with the connected client and an available server from the dashboard. Do not copy a server code from an old example. Availability can vary by plan, region, and product configuration.
Enter the verified local target
When Medusa and our client run on the same host, enter 127.0.0.1 and port 9000, provided that is the listener you verified. The target is an IP address and port, not a URL ending in /app.
Start the tunnel
Review the configuration and press Start. Creating a configuration does not start it. Copy the assigned HTTPS origin for the configuration handoff below, but do not share access yet.
Starting the tunnel makes the listener reachable immediately. Complete local authentication and secret checks beforehand. If you need time to edit configuration after learning the assigned origin, stop the tunnel during that work. If restarting produces a different origin, update the environment again before remote testing.
If our client runs elsewhere, 127.0.0.1 refers to that device, not the Medusa host. Use the Medusa host's reachable LAN address and test it from the client device first. Follow local network policy when configuring listener binding or host access.
Complete the public-origin configuration handoff
An origin consists of scheme, hostname, and optional port. It does not contain a path. For an assigned URL such as https://medusa-example.example/app, the origin is https://medusa-example.example. This example hostname is a placeholder, not a Localtonet endpoint.
Editing .env only works if the application reads those variables. Inspect the backend's medusa-config.ts. A typical Medusa configuration loads environment values from the working directory and maps them into projectConfig:
import { defineConfig, loadEnv } from "@medusajs/framework/utils"
loadEnv(process.env.NODE_ENV || "development", process.cwd())
module.exports = defineConfig({
projectConfig: {
databaseUrl: process.env.DATABASE_URL,
http: {
storeCors: process.env.STORE_CORS!,
adminCors: process.env.ADMIN_CORS!,
authCors: process.env.AUTH_CORS!,
jwtSecret: process.env.JWT_SECRET!,
cookieSecret: process.env.COOKIE_SECRET!,
},
},
})
This is an illustration of the mapping, not a replacement for your entire generated file. Preserve modules, plugins, and other generated options. Confirm that your actual configuration reads the variables, and remove insecure fallback secrets before exposure.
| Variable | Configuration property | Purpose |
|---|---|---|
ADMIN_CORS | http.adminCors | Allowed browser origins for Admin routes. |
STORE_CORS | http.storeCors | Allowed browser origins for Store routes. |
AUTH_CORS | http.authCors | Allowed browser origins for authentication routes. |
JWT_SECRET | http.jwtSecret | Private authentication signing material. |
COOKIE_SECRET | http.cookieSecret | Private cookie signing material. |
In the backend .env, add the actual public Admin origin to ADMIN_CORS and AUTH_CORS. Preserve local origins you still use. For this backend-only demonstration, do not add an imaginary storefront origin:
ADMIN_CORS=http://localhost:9000,https://medusa-example.example
AUTH_CORS=http://localhost:9000,https://medusa-example.example
Preserve any other legitimate origins required by your project. Do not include /app, /admin, or /store in these values. CORS is browser policy, not an authorization mechanism, and it does not block non-browser callers.
Generate separate strong secrets if the project contains development defaults. For example, run this command twice privately and place the distinct results in JWT_SECRET and COOKIE_SECRET:
node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))"
Do not replace established secrets casually: doing so can invalidate existing authentication material. Stop the development server with Ctrl+C and restart npm run dev from the backend directory so the process reloads its environment.
Storefront integration: identify which runtime makes the request
Installing the Next.js Starter is intentionally excluded here. A complete storefront integration also needs its required environment variables, a publishable API key associated with the intended sales channel, products available in that channel, and applicable region, inventory, shipping, and payment configuration.
Do not assume MEDUSA_BACKEND_URL must be public merely because a customer opens the storefront remotely. Next.js can execute backend calls on its server. If that server runs on the Medusa machine, http://localhost:9000 can be valid. If it runs in another container, virtual machine, or hosting environment, its localhost is different and it needs an address reachable from that runtime.
A direct browser request is different: localhost refers to the visitor's device. Such requests need a browser-reachable backend address and the appropriate Medusa CORS origins. A storefront that performs server-side requests or proxies calls may show only storefront requests in browser developer tools. Inspect the installed starter's SDK initialization, server actions, route handlers, and server logs before deciding which URL to change.
Publishable API keys are designed for Store API use and are not Admin secrets. They identify the applicable store access context, including associated sales channels. They do not grant administrative privileges, but still need correct configuration. Never substitute an Admin credential or secret API key for a publishable key.
Verify remote authentication before sharing access
Work from the database and local application outward. Keep the Medusa terminal visible. Confirm the selected Localtonet device remains connected and the tunnel is running.
- Retest locally after restarting. Open
http://localhost:9000/app, sign in, and load a protected page. - Test the target from our client device. If it is a separate machine, request the Medusa LAN address there before troubleshooting public access.
- Use an independent network. Open the public HTTPS URL ending in
/appfrom a phone with Wi-Fi disabled or another remote connection. - Use a private browser window. Confirm that administrative access requires authentication rather than relying on a cached session.
- Sign in remotely. Load the product list or another protected Admin page. Confirm its authenticated API request succeeds, not just the dashboard HTML.
- Sign out and retest. Verify that protected data is no longer accessible without authentication.
Also make a credential-free request to a protected Admin route:
curl -i https://YOUR_ASSIGNED_PUBLIC_HOST/admin/products
Expect an authentication rejection, not protected product data. A 404 or unrelated application response is not sufficient evidence that Medusa authorization works. Confirm you reached the intended service. Do not copy session cookies, bearer tokens, or complete network exports into support posts.
For the optional separate storefront integration, test both the browser-to-storefront and storefront-runtime-to-Medusa paths. Do not require browser traces to show direct public Medusa requests when calls are executed server-side.
Once these checks pass, share the URL only with intended collaborators through an appropriate channel. Stop the tunnel when the session ends. Delete its configuration if it is no longer needed. Host sleep, a stopped Medusa process, a disconnected client, or a stopped tunnel interrupts access.
Secure every route on the exposed listener
Public HTTPS protects browser connectivity to the tunnel edge; it does not supply Medusa authorization or turn a development server into a production service. Treat custom routes, uploads, debug endpoints, and integrations as part of the exposure review, not only the standard Admin interface.
- Use synthetic commerce data and sandbox integrations for demonstrations. Do not process real payments through this development workflow.
- Use unique Admin credentials and remove accounts that are no longer needed.
- Keep PostgreSQL and Redis private and restrict database privileges to the application’s needs.
- Keep device tokens, database URLs, signing secrets, and Admin credentials out of repositories and screenshots.
- Use precise CORS origins, but do not confuse them with access controls.
- Do not weaken cookie security or disable authentication to repair login failures.
- Review custom unauthenticated routes before publishing the listener.
- Stop temporary access promptly and follow the host network's policies.
An obscure hostname is not an access control. If you require an Admin-only surface or an audience restriction beyond Medusa's authentication, implement and test that control separately before starting the tunnel.
Production self-hosting: planning only
The Medusa deployment overview recommends separate server and worker instances for production and identifies PostgreSQL, Redis, and separately deployed storefronts. It recommends at least 2 GB of RAM for an optimal hosting experience, not as a capacity guarantee for every workload.
The supplied general deployment guide excerpt does not contain enough detail to reproduce a current production deployment. This article therefore does not provide guessed build, migration, worker, or Redis module commands. A development server exposed through Localtonet must not be presented as a completed production installation.
| Area | Required deployment decision | Acceptance check |
|---|---|---|
| Build and environment | Exact package versions, workspace, build output, startup directory, and environment loading. | A clean host can build and start the same release without development defaults. |
| Database migrations | Version-specific migration command and controlled release ordering. | Migrations succeed on a restored staging database before production. |
| Server and worker | Explicit modes, matching application versions, and correct Admin handling on the worker. | Requests and background jobs both work without unintended duplicate execution. |
| Redis infrastructure | Required session and infrastructure-module configuration for the selected version. | Each process connects to the intended private services; setting a URL alone is not assumed sufficient. |
| Supervision | Service user, restart behavior, boot startup, logging, and graceful shutdown. | Controlled process failure and host restart recover correctly. |
| Recovery | Database and asset backups, retention, restore procedure, and compatible application artifacts. | A timed isolated restore meets the required recovery objectives. |
Before an upgrade, save the current application artifact and lockfile, back up persistent data, and test migrations against a restored copy. Application rollback does not automatically reverse database migrations. If schema changes are incompatible, recovery may require a coordinated database restore and a plan for data written after the backup.
Monitor authenticated application behavior, worker failures, PostgreSQL and Redis connectivity, memory, disk space, and tunnel state if Localtonet is part of ingress. Avoid logging passwords, authorization headers, session cookies, or payment data. Test health at both the HTTP and business-workflow levels.
Our platform provides reachability to the configured service. It does not build or supervise Medusa, configure its workers, operate its databases, create application backups, or verify checkout workflows. Complete and test a version-specific deployment runbook before accepting real orders.
Troubleshoot from the inside outward
Node.js or dependency installation fails
Compare node --version with generator metadata and the generated backend's engines. Do not use v2.19 compatibility as proof for a later installation. Preserve the lockfile and use the package manager that created it when repairing dependencies.
The database responds but Medusa cannot connect
Repeat the application-role psql test. Verify the actual database, TCP address, role, and password. Check URL encoding separately from plain password authentication. For managed databases, verify TLS and network allow rules. Never resolve authentication failures by granting superuser access indiscriminately.
The development script or environment file is missing
Locate medusa-config.ts again and inspect the adjacent package. You may be at a monorepo root rather than apps/backend. Confirm the environment loader's working directory. Avoid creating a second unrelated .env simply because the intended one was not found.
Port 9000 is occupied
ss -ltnp 'sport = :9000'
Identify the listener before stopping anything. A stale generator process may already be running the correct application. If you intentionally change Medusa's port through supported configuration, update the tunnel target and local checks to match.
The tunnel is unavailable or shows another application
Confirm the correct device is connected, the tunnel was started, and the target matches the verified listener. Test the target directly from the client device. Stop the tunnel immediately if it publishes the wrong service, then correct the configuration.
The Admin loads but login fails
Inspect the failing request, response status, browser cookie warnings, and Medusa logs. Check exact public origins, environment loading, and whether the server was restarted. Look for unexpected redirects or direct browser requests to localhost. Do not “fix” the problem by opening CORS universally or removing authentication.
A separate storefront shows no products
Identify whether the failing request executes in the browser or on the Next.js server. Verify connectivity from that runtime, the publishable key's sales-channel association, product availability, and applicable region configuration. Absence of direct Medusa traffic in browser developer tools can be normal for server-side calls.
Frequently asked questions
Is this a production self-hosting guide?
No. It covers local Medusa development and temporary remote access. Production deployment and storefront installation are explicitly outside the demonstrated scope.
Does pinning create-medusa-app pin Medusa itself?
Not necessarily. Record the generator version separately from generated dependencies. Inspect the backend package versions and preserve the appropriate lockfile to establish the installation you actually obtained.
Where should I run backend commands?
Use the backend directory containing medusa-config.ts and its package configuration. The supplied current walkthrough uses apps/backend, but inspect your generated layout rather than assuming the repository root.
Does sharing the /app URL expose only Admin pages?
No. The tunnel forwards the HTTP listener, including all routes it serves, unless separately enforced routing restrictions exist. Medusa must continue to authorize protected operations.
Must a Next.js storefront use the public backend URL?
Only if that is the address required by the requesting runtime. Server-side calls can use a local address reachable from the Next.js server. Direct browser calls need an address reachable from the visitor's browser.
Do I need router port forwarding, and when does the tunnel stop working?
No inbound router port forwarding is required. Our client connects outbound. Access requires the selected client to remain connected, the tunnel to remain running, and Medusa to remain reachable at the configured target.
Share a verified Medusa development environment
Confirm your runtime and database requirements, verify Admin authentication locally, and use our HTTP tunnel for controlled remote testing. Review every route on the listener and stop access when the session ends.
Get Started Free →Corrections & updates
Substantive changes approved by the Localtonet editorial team are listed transparently below.
Localtonet is a secure multi-protocol tunneling and proxy platform designed to expose localhost, devices, private services, and AI agents to the public internet supporting HTTP/HTTPS tunnels, TCP/UDP forwarding, mobile proxy infrastructure, file server publishing, latency-optimized game connectivity, and developer-ready AI agent endpoint exposure from a single unified control plane.