Today we discuss how to create multi-websites in Magento 2 .
Magento allows you to setup multi-websites for your single installed Magento.
For example www.example.com is a main website and you want to like this www.example.com/newsetup/
Then you need to create newsetup dirctory(folder) on magento root dirctory.
Step 1. Find the website code
1. Go to Stores -> Settings -> All Stores and create a new website than a new store and a new store view.
you can use an already created store and store view the main thing you need to create is a new website.
2. Add the baseUrl to the particuler website .
Spep 2. Add the baseUrl to the particuler website
Go to Stores ->Settings Configuration ->General ->Web ->Base URLs and Secure as well.
Example : www.example.com/newsetup/
Spep 3. Copy the index.php and .htaccess files from magento root to new folder.
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';
Step 4. Create simlinks inside the new folder.
Go to Mageto root dirctory:
Command format : 1n -s full root path full root path/folder name
In my case full root path is /home/xyz/public_html
Example below :-
If Magento website running from pub dirctory:-
ln -s /home/xyz/public_html/pub/media/ /home/xyz/public_html/newsetup/ ln -s /home/xyz/public_html/pub/static/ /home/xyz/public_html/newsetup/ ln -s /home/xyz/public_html/app/ /home/xyz/public_html/newsetup/ ln -s /home/xyz/public_html/lib/ /home/xyz/public_html/newsetup/ ln -s /home/xyz/public_html/var/ /home/xyz/public_html/newsetup/
If Magento website running from root(without pub) dirctory:-
ln -s /home/xyz/public_html/pub/ /home/xyz/public_html/newsetup/ ln -s /home/xyz/public_html/app/ /home/xyz/public_html/newsetup/ ln -s /home/xyz/public_html/lib/ /home/xyz/public_html/newsetup/ ln -s /home/xyz/public_html/var/ /home/xyz/public_html/newsetup/
Run the above cammand from the cli and clear the magento cache.
Related Post on Price Range Filter In Magento 2