1

Is it possible to run two Magento 2 websites on a single domain? I want to share the user between this websites. but want to redirect them to different stores (same URL - without store code) after they login based on their user group. That two store will be having same catalogs and identical store view.

I'm just doing this for separate user experience, like to make available different payment method, shipping and catalog visibility based on the user group, that is not available in magento base setup.

2
  • I have one question, How can I use a single user account for two different Magento. both have different db, how can I manage it? Is it possible? also if I added same customer details in both databases then is it possible to login automatically for both site? Jan 12, 2019 at 10:29

4 Answers 4

3

here is the answer https://gist.github.com/thagxt/0f605f0a8a95c79302db0d2f04383788

we can create separate store in sub directory, so they run on same domain (no sub domain) and there is no need to make change in httpd or .htaccess

2
0

There's another way to do that, in Stores > Settings > Configuratio >web:

  1. Set your new site's url to that of the base_url(ex: www.website.com/)
  2. Set the option of 'add store Code in URLs' on.
0
  • Magento v2.4.*
  • LAMPP stack
  • OS - Ubuntu

Magento 2 single domain multi website

  • Create multiwebsite in magento2 and set base url /fr , /mx

  • Create sub directory inside pub dir

  • Copy pub/.htaccess and pub/index.php into sub dir

  • Update pub/fr/index.php

     <?php
     use Magento\Framework\App\Bootstrap;
    
     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] = 'DFR'; //Webite code as same in admin panel
     $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
     $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
    
     $bootstrap = Bootstrap::create(BP, $params);
     /** @var \Magento\Framework\App\Http $app */
     $app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
     $bootstrap->run($app);
    
  • Create symlinks for static, media and error files

     cd pub/fr 
     ln -s ../media media
     ln -s ../static static
     ln -s ../opt opt
     ln -s ../errors errors
    

Clear cache and redeploy

0

I created multi websites for AWS public EC2 domain and its ip address. Below are the steps I which followed.

  1. Create new website(code: webtwo), store and storeview in Magento admin
  2. Configure its base url in stores / configuration / General / Web
  3. Create site configuration for the new website under /etc/nginx/sites-available/

Consider below as an example

Create file name for webtwo

And the code would be:

server {
     listen 80;
     server_name x.xxx.xx.xxx;
     set $MAGE_ROOT /var/www/html/site;
     set $MAGE_RUN_CODE webtwo;
     set $MAGE_RUN_TYPE website;
     include /var/www/html/site/nginx.conf.sample;
}

Do not modify anything in magento file under /etc/nginx/sites-available/. If any changes required, then modify accordingly. Unless do not modify the file.

  1. Run nginx -t and confirm the changes are taken by Nginx

  2. Navigate to /etc/nginx/sites-enabled/ and run the command for creating symlink ln -s /etc/nginx/sites-available/webtwo webtwo

  3. Navigate to magento root directory and open the file nginx.confg.sample and add the below code

fastcgi_param MAGE_RUN_TYPE $MAGE_RUN_TYPE;
fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;

under # PHP entry point for main application

And it would look like

# PHP entry point for main application
location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {
    try_files $uri =404;
    fastcgi_pass   fastcgi_backend;
    fastcgi_buffers 1024 4k;

    fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=off";
    fastcgi_param  PHP_VALUE "memory_limit=756M \n max_execution_time=18000";
    fastcgi_read_timeout 600s;
    fastcgi_connect_timeout 600s;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    # START - Multisite customization
    fastcgi_param MAGE_RUN_TYPE $MAGE_RUN_TYPE;
    fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;
    # END - Multisite customization
    include        fastcgi_params;
}
  1. Now restart Nginx by systemctl restart nginx and the multi website site is ready and you can browse with the new ip / domain.

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.