Can you please provide the source/procedures to create a multi websites in magento 2. I have a google it regarding this,but none of the source/procedure didn't provide the path to create multi website/store.


5 Answers 5


Created multi-website in Magento, Steps to create a multistore in admin panel is same as like in magento1.x. Don't forget to change the base url and secure url for the new website/store. Once made changes in admin panel follow the below steps,

  1. Create a new folder in magento root and copy the index.php and .htaccess files from magento root to new folder.

  2. Edit the index.php which is in new folder


$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);

/** @var \Magento\Framework\App\Http $app */

$app = $bootstrap->createApplication('Magento\Framework\App\Http');



 $params = $_SERVER;
 $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'newstore'; //Webite code as same in admin panel
 $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
 $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
 /** @var \Magento\Framework\App\Http $app */

 $app = $bootstrap->createApplication('Magento\Framework\App\Http');


And also update bootstrap.php include path as below,


require __DIR__ . '/app/bootstrap.php';


require __DIR__ . '/../app/bootstrap.php';
  1. Create simlinks inside the new folder

    ln -s /home/example/example.com/html/app/ app

    ln -s /home/example/example.com/html/lib/ lib

    ln -s /home/example/example.com/html/pub/ pub

    ln -s /home/example/example.com/html/var/ var

Refer this

Please clear the var/generation, var/cache, and pub/static files and do the static content deployment.

  • I think we have to copy .htaccess also (together with index.php) from the root to the new folder.
    – Andrea
    Aug 8, 2016 at 20:53
  • 1
    can you setup multistores without hardcoding values in index.php or htaccess using add store codes to urls? seems to not work on magento2 Feb 3, 2017 at 11:25
  • Have you tried doing this with the suggested configuration for production environments and pointing the webroot to [Magento root]/pub? Jan 24, 2018 at 13:17
  • Do you guys have had any issue applying the same custom theme to both website? Mine the second website is loading assets from ../en_US/... instead of ../en_GB/.. any idea what could be ? Feb 26, 2018 at 20:10
  • Try deploy on specific theme with language code Feb 27, 2018 at 4:28

thanks to this resource

in Magento backend, go to Stores > All Stores Create here your architecture with different websites/store/storeview Note carefully the website codes, for instance,

  • USA store has code : us, and will be accessed by www.store.com
  • French store has code : fr, and will be accessed by www.store.fr
  • Spanish store has code : es, and will be accessed by www.store.es

in your Nginx config file (most likely in /etc/nginx/sites-enabled folder) add at the top of the config file :

map $HTTP_HOST $mage_run_code {
www.store.com us;
www.store.fr fr;
www.store.es es;

then, in the server block, add the declaration to listen to the 3 domains :

server {
 listen 80;
 server_name www.store.com www.store.fr www.store.es;

// whatever other config you get...

last, in the php config (the block starting with location ~ \. php $ {), add

fastcgi_param MAGE_RUN_TYPE website;
fastcgi_param MAGE_RUN_CODE $mage_run_code;

before the line (you will normally see other lines starting with fastcgi_param )

 include        fastcgi_params;

save your config file, restart your Nginx server et voila.




  • Introduction to multiple Magento stores and websites
  • Configure Magento
  • Set values for MAGE_RUN_TYPE and MAGE_RUN_CODE

Simple way tested on magento 2.2.5

Create a domain alias on your server example domain2.com

Edit index.php file in magento root

try {
    require __DIR__ . '/app/bootstrap.php';
} catch (\Exception $e) {
    echo <<<HTML
<div style="font:12px/1.35em arial, helvetica, sans-serif;">
    <div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
        <h3 style="margin:0;font-size:1.7em;font-weight:normal;text-transform:none;text-align:left;color:#2f2f2f;">
        Autoload error</h3>

$params = $_SERVER;
$customstore = array(
    'www.main.com'=>'main_website', // Website, Store or Storeview Code
    'www.domian2.com'=>'domain2_website'     // Website, Store or Storeview Code
    $websitecode = $customstore[$_SERVER['HTTP_HOST']];
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = isset($websitecode) ? $websitecode : '';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';//use website or store or view 
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
  • I am trying to create multi-website locally (Centos - Nginx) But getting error in Nginx configuration. Any help thanks magento.stackexchange.com/q/315027/57334 @Altravista thanks
    – zus
    Jun 25, 2020 at 13:34
  • Thank you it is working for me in 2.4.2 Jul 21, 2021 at 9:54

There are 6 steps to implement multiple website or store on the Magento2 site.

Step 1: Create a Root Category

Step 2: Create a new website

Step 3: Create a new store

Step 4: Create store views

Step 5: Configure the Store URL

Step 6: Map the vhost to work with Magento 2

  • I have read this : thecoachsmb.com/… May 16 at 10:12
  • I'm using apache server in ubuntu system, so how can i set host and domain for second website? can you please guide me. May 16 at 10:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.