Roadmap for setting up multiple websites with Apache

Setting up multiple stores consists of the following tasks:

  1. Set up websites, stores, and store views in the Admin.
  2. Create one Apache virtual host per Commerce website.

Step 1: Create websites, stores, and store views in the Admin

See Set up multiple websites, stores, and store views in the Admin.

Step 2: Create Apache virtual hosts

This section discusses how to set values for MAGE_RUN_TYPE and MAGE_RUN_CODE using the Apache server variable SetEnvIf in a virtual host.

For more information about SetEnvIf, see:

To create Apache virtual hosts:

  1. As a user with root privileges, open the virtual host configuration file in a text editor.

    For example, open /etc/httpd/conf/httpd.conf

  2. Locate the section starting with <VirtualHost *:80>.

  3. Create the following virtual hosts after any existing virtual hosts:

    <VirtualHost *:80>
       ServerName          mysite.mg
       DocumentRoot        /var/www/html/magento2/pub/
    </VirtualHost>
    
    <VirtualHost *:80>
       ServerName          french.mysite.mg
       DocumentRoot        /var/www/html/magento2/pub/
       SetEnv MAGE_RUN_CODE "french"
       SetEnv MAGE_RUN_TYPE "website"
    </VirtualHost>
    
    <VirtualHost *:80>
       ServerName          german.mysite.mg
       DocumentRoot        /var/www/html/magento2/pub/
       SetEnv MAGE_RUN_CODE "german"
       SetEnv MAGE_RUN_TYPE "website"
    </VirtualHost>
    
  4. Save your changes to httpd.conf and exit the text editor.

  5. Restart Apache:

    • CentOS: service httpd restart
    • Ubuntu: service apache2 restart