Create Multi Website/Stores in magento 2

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

Replace:

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

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

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

$bootstrap->run($app);

With:

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

 $bootstrap->run($app);

And also update bootstrap.php include path as below,

Replace:

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

With:

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.


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.


RTFM
https://devdocs.magento.com/guides/v2.3/config-guide/multi-site/ms_over.html

Contents

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