How to create multiple websites in Magento 2 Step By Step Guide - Magento Source24

How to create multiple websites in Magento 2 Step By Step Guide
How to create multiple websites in Magento 2 Step By Step Guide 

How to create multiple websites in Magento 2 Step By Step Guide : 

Today, I am going to share with you to Guys How to create multiple websites in Magento 2 Step By Step Guide .

As far as we know, Magento allows us to create multiple websites using on same a backend but with difference frontends. You have multiple websites and you want to use it on same a backend, this tutorial will help you to do it working.

Before doing this practice, you need to make sure that, you have two domains pointing to same the path on your hosting.

⇒ In my localhost, I have two domains named - 


1. website.vn

2. website.us


Both these websites pointing to same the path /var/www/html/magento/2.2.x/2.2.5

Let's do this practice, you need to follow steps by step:


➤ Step 1: Add a new Root Category : 


👉 Log into the backend and navigate to the Catalog → Catalog → Categories → Add Root Category

👉 Enter the Category Name

👉 Press the button Save.


➤ Step 2: Create a new website : 


👉> Go to the Stores → Settings → All Stores → Create Website

👉 Enter the Web Site Information

👉 Press the button Save Web Site.


➤ Step 3: Create a new Store for the second website : 


👉 Go to the Stores → Settings → All Stores → Create Store

👉 Enter the store information

👉 Press the button Save Store.


➤ Step 4: Create Default Store View for the second website : 


👉 Go to the Stores → Settings → All Stores → Create Store View

👉 Enter the Store view information

👉 Press the button Save Store View.


➤ Step 5: Setup the Base URL for the new website : 


👉 Go to the Stores → Settings → Configuration → General → Web

👉 On the top - left, in the box to view and manage the Store view, select the new website you just created. Go to the Base URLs and Base URLs (Secure) section.

👉 Modify to the new domain.

👉 Click the Save Config button.


➤ Step 6: Set values for the MAGE_RUN_TYPE and MAGE_RUN_CODE : 


⇒ Open the index.php file under application root directory

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


by these codes: 


switch($_SERVER['HTTP_HOST']) {

    case 'website.vn':

        $mageRunCode = 'base';

        $mageRunType = 'website';

    break;

    case 'website.us':

        $mageRunCode = 'second';

        $mageRunType = 'website';

    break;

}

$params = $_SERVER;

$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = $mageRunCode;

$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = $mageRunType;

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


➤ Step 7: Test and See the results : 


Run the comment line following:

👉 php bin/magento cache:flush

👉 Go the domains website.us and website.vn


⇒ For now, I will add some products to the website.us

⇒ Yeah, it works perfectly.

⇒ For now, I will change the theme for the website.us


There is no new website displaying there.

⇒ You need to run the indexer command line now.

yeah, it is showing now.


⇒ I change the default theme to the Magento Blank.

That is the results, you have two websites with the same one backend and with two different storefronts.




Deepak Kumar Bind

Success is peace of mind, which is a direct result of self-satisfaction in knowing you made the effort to become the best of which you are capable.

Post a Comment

If you liked this post please do not forget to leave a comment. Thanks

Previous Post Next Post