How to Set Up Multi-Store and Multi-Website in Magento 2
Magento 2 supports running multiple storefronts from a single installation. This enables businesses to manage multiple brands, languages, or regions from one admin panel with shared product catalogs, customer databases, and order management. Getting the hierarchy and configuration right from the start prevents issues with caching, SEO, and content delivery.
Understanding the Hierarchy
Magento uses a three-level hierarchy: Website → Store → Store View. Each level controls different aspects of the configuration.
Website
The top level. Each website can have:
- Its own base URL and domain
- Separate product pricing
- Independent customer accounts (customers cannot share accounts across websites by default)
- Different payment and shipping methods
Use multiple websites when you need completely separate catalogs or pricing structures (e.g., B2B and B2C operations, or different regional pricing).
Store
The middle level, sitting under a website. Each store:
- Has its own root category (determining the product catalog tree)
- Shares the website's pricing and customer base
- Can have a different navigation structure
Use multiple stores when you need different category structures on the same domain (e.g., a clothing store and a home goods store sharing the same customer accounts).
Store View
The lowest level, sitting under a store. Each store view:
- Represents a language/locale translation
- Shares the parent store's category tree and product catalog
- Can have different CMS content translations
- Has its own locale settings (language, currency display format)
Use multiple store views for multi-language support (e.g., English, German, French versions of the same store).
Configuration Steps
Creating the Structure
- Create a Website: Go to Stores → All Stores → Create Website. Set the website name and code (alphanumeric, lowercase, used internally).
- Create a Store: Under the new website, create a store and assign it a root category.
- Create Store Views: Under the store, create one store view per language/locale.
Setting Base URLs
For each store view or website, configure the base URL under Stores → Configuration → General → Web (switch scope to the appropriate store view).
Common URL patterns:
- Subdomain:
en.example.com,de.example.com - Subdirectory:
example.com/en/,example.com/de/ - Separate domains:
example.com,example.de
Web Server Configuration
For subdomain or separate domain setups, the web server (Nginx or Apache) must route requests to the correct Magento store view. This is done by setting the MAGE_RUN_TYPE and MAGE_RUN_CODE environment variables.
Nginx example:
server {
server_name de.example.com;
set $MAGE_RUN_CODE "de_store";
set $MAGE_RUN_TYPE "store";
# ... rest of Magento nginx config
}
Hreflang Configuration
Hreflang tags tell search engines which language version of a page to show in search results for different regions. Magento handles hreflang differently for products/categories versus CMS pages.
Products and Categories
Hreflang tags for product and category pages are generated automatically when multiple store views exist and the SEO extension is configured to output hreflang tags. No manual configuration is needed for these page types.
CMS Pages (Including Homepage)
CMS pages, including the homepage, require manual hreflang configuration. Magento does not automatically link CMS pages across store views because CMS pages are independent entities -- even if two CMS pages have the same URL key in different store views, Magento does not assume they are translations of each other.
To configure hreflang for CMS pages:
- Go to Content → Pages
- Open the CMS page
- Navigate to the Alternate Settings (or "Alternate Group") section
- Select the corresponding CMS pages in other store views that represent translations of this page
This must be done for every CMS page that has translations, including the homepage.
Cookie Domain Configuration
For multi-domain setups, configure the cookie domain per store view to prevent session conflicts.
Go to Stores → Configuration → General → Web → Session Cookie Management and set:
- Cookie Domain: The domain for cookies (e.g.,
.example.comfor subdomains, or the specific domain for separate domains) - Cookie Path: Usually
/
If using subdomains under the same parent domain, set the cookie domain to .example.com (with leading dot) to share sessions across subdomains. For completely separate domains, set each domain's cookie configuration independently.
Multi-Server and Multi-VM Setups
When running Magento across multiple servers or VMs (e.g., behind a load balancer), ensure:
- Generated files exist on all nodes. Files like
generated/metadata/,generated/code/, and extension-generated files (e.g.,instant.json) must be available on every server. Use a shared filesystem (NFS), rsync, or symlinks to keep them in sync. - Media storage is shared across all nodes (shared NFS mount or S3-compatible storage).
- Session storage uses a centralized backend (Redis) rather than filesystem sessions.
- Cache storage uses a centralized Redis instance accessible from all nodes.
Post-Configuration Steps
After setting up a multi-store configuration:
- Reindex:
php bin/magento indexer:reindex - Flush cache:
php bin/magento cache:flush - Regenerate sitemaps: Generate a new sitemap for each store view, as URL structures may have changed
- Verify hreflang: Use browser developer tools to check that hreflang tags appear correctly on all page types
Store Emulation for Translations
When running CLI commands or cron jobs that send emails or generate content for specific store views, Magento must emulate the target store view to load the correct translations and configuration. This is handled automatically by Magento's cron system, but custom scripts and third-party integrations may need to explicitly emulate the store:
$storeManager->setCurrentStore($storeViewId);
If emails or generated content appear in the wrong language, verify that the originating process correctly emulates the target store view.