15

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.

22

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.

  • 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
4

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.

2

RTFM
http://devdocs.magento.com/guides/v2.0/config-guide/bootstrap/mage-run.html

Contents

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

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>
    </div>
    <p>{$e->getMessage()}</p>
</div>
HTML;
    exit(1);
}

$params = $_SERVER;
$customstore = array(
    'www.main.com'=>'main_website', // Website, Store or Storeview Code
    'www.domian2.com'=>'domain2_website'     // Website, Store or Storeview Code
    );
if(isset($customstore[$_SERVER['HTTP_HOST']]))
    $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');
$bootstrap->run($app);

protected by Community Feb 8 '17 at 8:10

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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