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.


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 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';

3) Create a 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.

| improve this answer | |
  • I think we have to copy .htaccess also (together with index.php) from the root to the new folder. – Andrea Aug 8 '16 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 – Claudiu Creanga Feb 3 '17 at 11:25
  • Have you tried doing this with the suggested configuration for production environments and pointing the webroot to [Magento root]/pub? – Facundo Capua Jan 24 '18 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 ? – Juliano Vargas Feb 26 '18 at 20:10
  • Try deploy on specific theme with language code – saravanavelu Feb 27 '18 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.

| improve this answer | |



  • Introduction to multiple Magento stores and websites
  • Configure Magento
  • Set values for MAGE_RUN_TYPE and MAGE_RUN_CODE
| improve this answer | |

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');
| improve this answer | |

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