How to setup multiple websites, stores and store views in magneto 2?

Create a root category - Catalog-> Categories-> Add Root Category

Create a website, store and store view - Stores-> All Stores

2.1 Create Website -> Create Website (Ex- Berlin Website) 2.2 Create Store -> Select the website for which you want to create store and select root category which you created in step-1 2.3 Create Store View -> Select the store which you created in step-2.2 and must set the status as enabled

Set the Base Url and Secure Base Url link - Stores-> Settings-> Configuration-> General-> Web

(Ex- Your base url http://127.0.0.1/magento2.4.1/) 3.1 Change scope(left top corner dropdown) to the website you created in step-2.1 (only select the website not store view i.e. Berlin Website) 3.2 Change links both in Base Url, Base Link Url and Secure Base Url, Secure Base Link Url (http://127.0.0.1/magento2.4.1/berlin/) 3.3 Save config

Open magento root directory - (Ex- magento2.4.1)

4.1 Create a folder with the same name in link (here berlin) 4.2 Copy index.php and .htaccess from magento root folder and paste it in berlin 4.3 Open index.php and replace :- $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER); /** @var \Magento\Framework\App\Http $app */ $app = $bootstrap->createApplication(\Magento\Framework\App\Http::class); $bootstrap->run($app); with :- $params = $_SERVER; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'berlin'; (Put here the webiste code which you given in step-2.1) $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::class); $bootstrap->run($app);

Now run the below commands in berlin folder (replace the path below with the full path to the root of your Magento)-

ln -s /var/www/html/magento2.4.1/app/ app ln -s /var/www/html/magento2.4.1/lib/ lib ln -s /var/www/html/magento2.4.1/pub/ pub ln -s /var/www/html/magento2.4.1/var/ var

Run the below commands in magento root folder

sudo php bin/magento setup:upgrade sudo php bin/magento setup:di:compile sudo php bin/magento setup:static-content:deploy -f sudo php bin/magento indexer:reset sudo php bin/magento indexer:reindex sudo php bin/magento cache:clean sudo chmod -R 777 var pub

Check the new Url (http://127.0.0.1/magento2.4.1/berlin/)

Read Entire Article