Autoscale Magento in the cloud

Autoscale Magento in the cloud

September 23, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Autoscale Magento in the cloud

Autoscale Magento in the Cloud: A Comprehensive Guide

As you embark on your e-commerce journey with Magento, hosting your website on the cloud offers numerous benefits, including scalability and cost-efficiency. In this article, we’ll explore how to implement an autoscaling architecture for your Magento site using AWS services like Auto Scaling groups, Elastic Load Balancing (ELB), and Multi-AZ RDS.

Understanding the Challenge

Magento stores the base URL of its webserver directly in the database under the core_config_data table. This presents a challenge when you want to use multiple servers connected to a single DB instance for horizontal scaling during high load conditions.

The relevant rows in the core_config_data table look like this:

config_id   scope     scope_id    path                      value
5           default   0           web/unsecure/base_url     http://server1.com/magento/
6           default   0           web/secure_base_url       https://server1.com/magento/

As you can see, the value column specifies the URL address of the Magento installed web server. If you try to run multiple instances sharing a single database, only one base URL will be stored.

Solving the Base URL Issue

To overcome this limitation, we need to ensure that each instance has its own unique base URL in the shared database. Here’s how you can achieve this:

  1. Create Custom Config XML Files: When setting up your Magento instances, create custom config XML files for each server (let’s call them server1.xml and server2.xml). In these files, define the base URLs specific to each instance.

    For server1.xml:

    <?xml version="1.0"?>
    <config>
        <global>
            <web>
                <secure>
                    <base_url>https://server1.com/magento/</base_url>
                </secure>
                <unsecure>
                    <base_url>http://server1.com/magento/</base_url>
                </unsecure>
            </web>
        </global>
    </config>
    

    For server2.xml:

    <?xml version="1.0"?>
    <config>
        <global>
            <web>
                <secure>
                    <base_url>https://server2.com/magento/</base_url>
                </secure>
                <unsecure>
                    <base_url>http://server2.com/magento/</base_url>
                </unsecure>
            </web>
        </global>
    </config>
    
  2. Deploy Config Files: Deploy these XML files to the respective servers’ app/etc directory, replacing the default config file (config.php).

  3. Clear Cache: After deploying, clear the Magento cache from both servers.

  4. Use Auto Scaling and ELB: Set up your AWS Auto Scaling group with Elastic Load Balancing (ELB). The Auto Scaling group will launch new EC2 instances based on predefined rules or custom CloudWatch alarms. The ELB will distribute traffic evenly across these instances.

Additional Best Practices

  1. Use a Load Balancer: A load balancer helps to distribute incoming application traffic across multiple servers, ensuring no single server bears the entire load.

  2. Implement Caching: Utilize caching mechanisms like Varnish or Redis to improve performance and reduce database queries.

  3. Optimize Images: Use image optimization techniques to reduce the size of your product images and improve page loading times.

  4. Regularly Update Magento: Keep your Magento installation up-to-date with the latest security patches and feature updates. Laravel Company has covered this topic in detail.

Conclusion

Autoscaling a Magento website on the cloud requires careful planning to handle the base URL issue effectively. By creating custom config XML files for each server and utilizing AWS services like Auto Scaling groups and ELB, you can achieve horizontal scaling during high load conditions without compromising your site’s functionality.

Remember to regularly monitor your setup, optimize performance where possible, and keep your Magento installation up-to-date. With this approach, you’ll have a scalable and robust e-commerce platform ready for growth.

Don’t hesitate to reach out if you need further assistance or would like to discuss your specific use case in more detail.

Database Configuration Errors

Our network