8

I know this question may have been previously asked but I followed many reference links, but I cannot do this thing so please help me achieve it.
base URL = http://127.0.0.1/magento22/

1) Create a site in Magento with 4 languages

  • Deutschland (German)
  • Francais (French)
  • Nederland (Dutch)
  • Switzerland (Swiss)

2) Change code in index.php

<?php
/**
 * Application entry point
 *
 * Example - run a particular store or website:
 * --------------------------------------------
 * require __DIR__ . '/app/bootstrap.php';
 * $params = $_SERVER;
 * $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'website2';
 * $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);
 * --------------------------------------------
 *
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

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;
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
switch ($actual_link) 
{
    case 'http://127.0.0.1/magento22/deutschland/':
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'deutschland'; 
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website'; 
        break; 
    case 'http://127.0.0.1/magento22/france/':
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'france'; 
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website'; 
         echo "11";
        break; 
    case 'http://127.0.0.1/magento22/nederland/':
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'nederland'; 
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website'; 
        break; 
    case 'http://127.0.0.1/magento22/switzerland/':
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'switzerland'; 
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website'; 
        break; 
    case 'http://127.0.0.1/magento22/':
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'base'; 
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website'; 
        break;     
    default: 
        $params = $_SERVER;
        break; 

}

$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);
4
  • Do you have assign website URL in admin as per website? Commented Feb 9, 2018 at 5:13
  • yes i have assign url as per index.php. @SureshChikani Commented Feb 9, 2018 at 5:27
  • Above code working or not as per website? Commented Feb 9, 2018 at 5:42
  • if i run 127.0.0.1/magento22/deutschland this url than google code of this website change, but 404 page display and also if i click any of the link it redirect to base link 127.0.0.1/magento22 Commented Feb 9, 2018 at 6:14

3 Answers 3

6

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.

enter image description here

enter image description here

Final Step:-store->configuration->general->web->select store view and add base URL for Each Store

14
  • 3) Create a simlinks inside the new folder, I have to copy my app, lib, pub and var inside new folder? Commented Feb 9, 2018 at 6:00
  • docs.nexcess.net/article/… Commented Feb 9, 2018 at 6:01
  • I can not understand simlinks where i have to do this think. Commented Feb 9, 2018 at 6:15
  • it's simple first you only 2 website create and check. Commented Feb 9, 2018 at 6:20
  • check update image Commented Feb 9, 2018 at 6:35
1

If The Server Is NGINX then Follow Below Steps.

Here is the scenario. We have two different websites, and each website has two different store views as follows:

Website 1

  • Website 1 (E-commerce)
  • Website 1 (Venda Assistida)

Website 2

  • Website 2 (E-commerce)

  • Website 2 (Venda Assistida)

In my solution, we are going to change some configuration in Magento Admin. Then we are going to create some sub-folders, and finally we are going to modify nginx.conf.

First of all, we need to make some configuration change in the Magento Admin. Go to Stores -> Configuration -> General -> Web. We need to change Base URLs for each store view.

For Default Config Please provide the following configuration for default config.

enter image description here

For Website 1 (E-commerce) and Website 1 (Venda Assistida)

Please provide the following configuration for all Website 1 store views.

enter image description here

For Website 2 (E-commerce) and Website 2 (Venda Assistida)

Please provide the following configuration for all Website 2 store views.

enter image description here

Secondly, we need to create website1 and website2 folders in the /pub directory. In the final, you should have the following folders:

  • MAGENTO_ROOT/pub/website1
  • MAGENTO_ROOT/pub/website2

Copy the pub/index.php file into these directories. Then we will make some changes in MAGENTO_ROOT/pub/website1/index.php and MAGENTO_ROOT/pub/website2/index.php.

Content of MAGENTO_ROOT/pub/website1/index.php I have only changed 3 lines:

1st Line: require __DIR__ . '/../../app/bootstrap.php';

2nd Line: $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'website1';

3rd Line: $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';

<?php
/**
 * Public alias for the application entry point
 *
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

use Magento\Framework\App\Bootstrap;
use Magento\Framework\App\Filesystem\DirectoryList;

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;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'website1';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
$params[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = [
    DirectoryList::PUB => [DirectoryList::URL_PATH => ''],
    DirectoryList::MEDIA => [DirectoryList::URL_PATH => 'media'],
    DirectoryList::STATIC_VIEW => [DirectoryList::URL_PATH => 'static'],
    DirectoryList::UPLOAD => [DirectoryList::URL_PATH => 'media/upload'],
];

$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);

For the final touch, we need to modify nginx.conf in your MAGENTO_ROOT directory. Please put the following configuration into your nginx.conf.

location /website1 {
    root /website1;
    if (!-e $request_filename) {
        rewrite ^/(.*)$ /website1/index.php last;
        break;
    }
}

location /website2 {
    root /website2;
    if (!-e $request_filename) {
        rewrite ^/(.*)$ /website2/index.php last;
        break;
    }
}

After all this configurations and modifications, you will be able to use websites as sub-folders.

2
  • Hello Jaimin, can i get docs for Create magento 2.3 Multi Store in Wamp Localhost
    – zus
    Commented Jan 3, 2019 at 6:11
  • Where should i create a subfolder for symbolic links, Root folder or under the pub folder? @Jaimin, Teja Bhagavan Kollepara
    – zus
    Commented Jun 30, 2020 at 3:11
0

Check with below code

<?php
/**
 * Application entry point
 *
 * Example - run a particular store or website:
 * --------------------------------------------
 * require __DIR__ . '/app/bootstrap.php';
 * $params = $_SERVER;
 * $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'website2';
 * $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);
 * --------------------------------------------
 *
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

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;
$params[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = [
    DirectoryList::PUB => [DirectoryList::URL_PATH => ''],
    DirectoryList::MEDIA => [DirectoryList::URL_PATH => 'media'],
    DirectoryList::STATIC_VIEW => [DirectoryList::URL_PATH => 'static'],
    DirectoryList::UPLOAD => [DirectoryList::URL_PATH => 'media/upload'],
];

//$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
switch ($_SERVER['HTTP_HOST'])
{
    case 'http://127.0.0.1/magento22/deutschland/':
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'deutschland';
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
        break;
    case 'http://127.0.0.1/magento22/france/':
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'france';
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
        echo "11";
        break;
    case 'http://127.0.0.1/magento22/nederland/':
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'nederland';
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
        break;
    case 'http://127.0.0.1/magento22/switzerland/':
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'switzerland';
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
        break;
}

$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);
7
  • I want to use the same media, pub, static view. Commented Feb 9, 2018 at 6:19
  • Please check with this code. Commented Feb 9, 2018 at 6:20
  • Please check it with my updated code. Commented Feb 9, 2018 at 6:41
  • Uncaught Error: Class 'Bootstrap' not found in /var/www/html/magento22/index.php:36 Commented Feb 9, 2018 at 6:46
  • with this code $_SERVER['HTTP_HOST'], i can get 127.0.0.1 Commented Feb 9, 2018 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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