Magento 2 Multi-Store Setup

🛒 Magento 2 Multi-Store Setup – One Installation, Many Stores

Want to run multiple shops from one Magento 2 installation? That’s what Multi-Store is all about! It lets you create multiple storefronts—each with different domains, products, and settings—while managing them all from a single admin panel.

📦 How Magento 2 Multi-Store Works

  • Website – Top-level container. Can have its own customers, orders, and settings.
  • Store – Each website can have one or more stores (catalogs).
  • Store View – Each store can have multiple views (languages, currencies, etc.).

⚙️ Step-by-Step Multi-Store Setup

1. Create a New Website

  1. Go to Stores » Settings » All Stores
  2. Click Create Website
  3. Fill in the name, code (e.g., secondwebsite), and save

2. Create a New Store Under the Website

  1. Click Create Store
  2. Select the new website, give the store a name, assign root category

3. Create a New Store View

  1. Click Create Store View
  2. Assign to your new store and name it (e.g., English or Default View)

4. Add the Website in env.php or Use .htaccess

You can point domains using Apache/Nginx or modify index.php.

🔧 Sample Apache VirtualHost for Multi-Store


    ServerName mystore1.com
    DocumentRoot /var/www/html/magento2/pub
    SetEnv MAGE_RUN_TYPE website
    SetEnv MAGE_RUN_CODE base



    ServerName mystore2.com
    DocumentRoot /var/www/html/magento2/pub
    SetEnv MAGE_RUN_TYPE website
    SetEnv MAGE_RUN_CODE secondwebsite

Try It Now

🌍 Example of Different Domains

  • mystore1.com → Main Website
  • mystore2.com → Second Website

Point both domains to the same Magento 2 installation. Magento will detect the correct website using MAGE_RUN_CODE.

🧪 Optional: Change index.php Instead

You can also change index.php logic to load websites dynamically based on domain.

switch ($_SERVER['HTTP_HOST']) {
    case 'mystore1.com':
        $_SERVER['MAGE_RUN_CODE'] = 'base';
        $_SERVER['MAGE_RUN_TYPE'] = 'website';
        break;
    case 'mystore2.com':
        $_SERVER['MAGE_RUN_CODE'] = 'secondwebsite';
        $_SERVER['MAGE_RUN_TYPE'] = 'website';
        break;
}

Try It Now

✅ Final Steps

  • Flush Magento Cache
  • Reindex data: php bin/magento indexer:reindex
  • Deploy static content if needed

🎯 Conclusion

With Magento 2’s multi-store feature, you can manage many shops, catalogs, and languages all under one roof. Whether you’re building regional stores or brand-based sub-sites, Magento has you covered!