top of page

Magento 2 Multi Website with Apache2

Need to create websites, stores and stores views from Magento admin

Main website: Magento already creates the main website while we installing.

Website One: Store -> All stores -> Create Website -> set website code whatever you want, in this tutorial we set webiste_code as websiteone Store -> All stores -> Create Store -> set store code whatever you want, in this tutorial we set store_code as storeone Store -> All stores -> Create Store View -> Assign to storeone -> Status must be enabled

Website Two: Store -> All stores -> Create Website -> set website code whatever you want, in this tutorial we set webiste_code as websitetwo Store -> All stores -> Create Store -> set store code whatever you want, in this tutorial we set store_code as storetwo Store -> All stores -> Create Store View -> Assign to storetwo -> Status must be enabled

Similarly, we can create n number of websites, stores and store views.

After that we need to update the base url for the created website and stores. 1. local.main.com – which is main website 2. local.websiteone.com 3. local.websitetwo.com

After that, we need to create vhost for the above-created websites in /etc/apache2/sites-available/local.main.com.conf

<VirtualHost *:80>
    ServerAdmin xxxxxxx@xxxxxxxx.com
    ServerName local.main.com
    ServerAlias local.main.com
    DocumentRoot /var/www/html/magento/pub
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    <Directory /var/www/html/magento>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin xxxxxxx@xxxxxxxx.com
    ServerName local.websiteone.com
    ServerAlias local.websiteone.com
    DocumentRoot /var/www/html/magento/pub
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    SetEnv MAGE_RUN_CODE "websiteone"
    SetEnv MAGE_RUN_TYPE "website"
    <Directory /var/www/html/magento>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin xxxxxxx@xxxxxxxx.com
    ServerName local.websitetwo.com
    ServerAlias local.websitetwo.com
    DocumentRoot /var/www/html/magento/pub
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    SetEnv MAGE_RUN_CODE "websitetwo"
    SetEnv MAGE_RUN_TYPE "website"
    <Directory /var/www/html/magento>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
    </Directory>
</VirtualHost>

After creating the above file we need to enable the vhost by running the below command.

a2ensite local.main.com

After that, we need to restart the apache server to changes gets reflects.

sudo service apache2 restart

The final step, we need to map our hostname with our IP in /etc/hosts, in my case it is 127.0.0.1

127.0.0.1  local.main.com  local.websiteone.com  local.websitetwo.com

That’s all, open the websites URL in the browser. If you configuring everything correct, you can access the all the websites.

Recent Posts

See All

Comments


Follow Me

  • LinkedIn
  • Twitter
  • Facebook
  • YouTube
  • Instagram

©2021 by Bilal Usean. Proudly created with Wix.com

bottom of page