What is the proper way to configure Magento + Apache while running multiple stores on multiple domains?

What is the proper way to configure Magento + Apache while running multiple stores on multiple domains?

July 28, 2026 · Illustrated author avatarBy Stefan Bogdanescu
What is the proper way to configure Magento + Apache while running multiple stores on multiple domains?

Configuring Magento + Apache for Multiple Domains: A Comprehensive Guide

Multiple domains are a common requirement for e-commerce platforms like Magento, allowing you to manage several stores from a single installation. However, configuring the Apache server to handle these multiple domains can be quite challenging. This guide aims to provide a clear and concise explanation of how to achieve this properly.

Understanding the Magento Architecture

Before we dive into Apache configuration, let’s first understand the basic structure of a Magento setup with multiple stores.

In your case, you have:

Main Web Site -> Main Web Site Store -> Default Store View
www.site1.com    -> Main Store      -> site1_english
www.site2.com    -> Main Store      -> site2_english

Here:

  • The first column represents the domain.
  • The second column is the “Store”. In this context, it’s a bit misleading as we’re focusing on the lowest level - the “Store View”.
  • The last column is the actual store view within the Magento system.

Physically Placing Your Files

Most developers prefer to leave the core Magento files untouched. This means you should place them directly in your document root:

/var/www/html/magento

This allows for a clean separation between the installation and your domain-specific configurations. You can later add other folders like /wordpress if required.

Apache Configuration

The key to handling multiple domains lies in the proper configuration of your Apache server. Here’s an example of how you should set up your virtual hosts:

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
    ServerName site1.com
    ServerAlias www.site1.com
    DocumentRoot /var/www/html/magento

    <Directory /var/www/html/magento/>
        AllowOverride All
    </Directory>

    # Other directives here
    SetEnv MAGE_RUN_CODE "site1"
    SetEnv MAGE_RUN_TYPE "website"

</VirtualHost>

<VirtualHost *:80>
    ServerName site2.com
    ServerAlias www.site2.com
    DocumentRoot /var/www/html/magento

    <Directory /var/www/html/magento/>
        AllowOverride All
    </Directory>

    # Other directives here
    SetEnv MAGE_RUN_CODE "base"
    SetEnv MAGE_RUN_TYPE "site2_en"

</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/html/nowhere
</VirtualHost>

Understanding the Configuration

Virtual Hosts

Each domain (site1.com and site2.com) has its own virtual host. This allows Apache to route requests to the appropriate directory based on the domain.

SetEnv Directives

The SetEnv directives are crucial for Magento’s multi-store functionality:

  • MAGE_RUN_CODE: This represents the store code in your Magento installation. For websites, it should match the “Store Code” field; for store views, it matches the “Code” field.
  • MAGE_RUN_TYPE: This determines whether you’re running a site or a store view.

The Default Store View

In your setup:

Main Web Site -> Main Web Site Store -> Default Store View

This is the base store with no specific domain associated. When you access the IP address directly, Magento redirects to this default store view because it doesn’t recognize any of the configured domains (site1.com or site2.com).

Common Issues and Solutions

Redirects to the Default Store View

When you navigate to www.site1.com, you’re redirected to the default store view instead of staying on the site1 domain. This happens because Magento is looking for a match between the current request’s host and the configured BASE URL in your stores.

To fix this:

  1. Go to Admin Panel > System > Configuration.
  2. Select your scope (for example, “Default Config” or “Default Store View”).
  3. Under General, find Web.
  4. Change the Base URLs (Secure) field for each store view to match its respective domain:
    • For site1_english, set it to http(s)://www.site1.com/.
    • For site2_english, set it to http(s)://www.site2.com/.
  5. Save the configuration.

The “Nowhere” Site

If you can’t access your nowhere site, ensure that:

  • Your nowhere folder actually exists at /var/www/html/nowhere/.
  • It contains an index.html file with a simple message like “no where”.
  • There are no redirecting rules in the .htaccess file for this domain.

Conclusion

Configuring Magento to run on multiple domains requires a thorough understanding of both your Magento installation and your Apache server settings. By following the guidelines outlined above, you can ensure a clean setup that handles each domain independently while still sharing the core Magento files.

Remember, the key is to keep your core files untouched and use virtual hosts in your Apache configuration to route requests based on the domain name. With proper store view configurations in your Magento admin panel, you should be able to manage multiple stores seamlessly from a single installation.

For more detailed information on Magento’s multi-store capabilities and Apache configuration best practices, I recommend checking out the official Magento documentation.

Configuration

Our network