1

I'm trying to create new store & website which will run at http://127.0.0.1/lapis/in/. Here is the process I've followed.

1. Created new store, website and store view named Indian Store, Indian website & Indian Store view respectively with website code in.
2. In Stores->Configuration->Web changed website URL to http://127.0.0.1/lapis/in/.
3. Assigned category at products->Categories after switching store view to Indian Store view.

  1. Created folder named in inside root magento installation with 2 files index.php and .htaccess with following code
    index.php code inside in directory
$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'in';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
$app = $bootstrap->createApplication('..\Magento\Framework\App\Http');
$bootstrap->run($app);
  1. Copied .htaccess root file inside in directory and added
    RewriteBase /in/
    Now when I'm navigating to http://127.0.0.1/lapis/ , it works fine but http://127.0.0.1/lapis/in/ throws 500 server error. I'm missing something here or my process of creating new website is wrong?
0

2 Answers 2

1
  1. In $app = $bootstrap->createApplication('..\Magento\Framework\App\Http'); $bootstrap->run($app); you should not use '..', as it's class name
  2. I'd also suggest to check your web server logs to better understand the issue.
7
  • Thanks. I was able to fix it with help of server logs. Page is loading static contents are not deployed to in/pub directory. Developer mode is on and also I've deployed content manually using php bin/magento setup:static-content:deploy . It is trying to use js/css resources from path http://127.0.0.1/lapis/in/pub/ but nothing is deployed in in/pub/ directory. Is there a different method to deploy static content for different websites?
    – amitshree
    Commented Jan 23, 2016 at 19:51
  • 1
    They should not be deployed in in/pub, all static assets should remain in pub. What you can do to fix it is to specify custom Base URL for Static View Files in Stores > Configuration > Web. It should point to regular pub, not to in/pub, which becomes default path when you specify custom Base URL for the website.
    – BuskaMuza
    Commented Jan 24, 2016 at 1:58
  • i have set multiple website but in new website css not render properly. I have set luma theme for new website but css not render. which issue may be possible for this? Commented Apr 5, 2016 at 13:12
  • @rakesh, have you specified specify custom Base URL for Static View Files?
    – BuskaMuza
    Commented Apr 6, 2016 at 2:26
  • which url we have to defined at that location, plz suggest me. Commented Apr 6, 2016 at 5:22
4

Here I am sharing working code for create multiple website in magento2 (2.0.4)

Create new sub website folder in Magento root folder.

Copy your Magento root index.php and .htaccess files and paste it new created website folder.

Open index.php file from new website folder and replace code

$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] = 'website_code'; 
    $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
    $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
    $app = $bootstrap->createApplication('\Magento\Framework\App\Http');
$bootstrap->run($app);

Now create new sub website with it's store and store view. -

  • Create a new sub website.

  • Create a new store with select sub website and sub website category.

  • Create a new store view with select sub website store.

Set theme for new created sub website.

Stores >> Configuration >> Select Sub Website from store view drop down >> Design >> Design Theme >> select theme for Sub Website and save. (We can set Magento Blank theme for testing purpose)

set new sub website URLs like this

Please got to Admin >> Stores >> Configuration >> Select your Sub Website from store view drop down >> Web >> Base URLs

Base URL : http://1270.0.1/magento-2.0.4/sub_website/

Base Link URL : http://1270.0.1/magento-2.0.4/sub_website/

Base URL for Static View Files : http://1270.0.1/magento-2.0.4/pub/static/

Base URL for User Media Files : http://1270.0.1/magento-2.0.4/pub/media/

And do the same for Base URLs (Secure)

Now Run command for deploy static content : Now run command for clean cache :

Done !!!

Now run and check base and new created website on browser.

Like :

Base website URL : http://1270.0.1/magento-2.0.4/

You will see this website selected category and theme

Sub website URL : http://1270.0.1/magento-2.0.4/sub_website/

You will see this website category and theme

If display all content properly then it is Done !!!

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