Setting Up Multiple Magento Stores Locally on MAMP
As an experienced developer working with e-commerce platforms like Magento, I often encounter scenarios where clients need to set up multiple stores locally for development or testing purposes using tools like MAMP (My Apache + MySQL + PHP). This allows for isolated environments that mimic the production setup.
Understanding the Multi-Store Configuration
Magento’s multi-store functionality enables you to manage multiple stores from a single installation. Each store shares the same media files, themes, and extensions, but has its own configuration settings like URLs, currency, and languages.
To achieve this locally with MAMP, we’ll need to configure both your Apache server (for virtual hosts) and Magento’s core configuration files.
Configuring Your Apache Virtual Hosts
Firstly, let’s set up the virtual hosts on your MAMP installation. In the httpd/conf/extra/httpd-vhosts.conf file under your MAMP folder:
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/siteA"
ServerName siteA.local
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/siteB"
ServerName siteB.local
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/siteC"
ServerName siteC.local
</VirtualHost>
This configuration points each of your local domains to the respective Magento installations.
Adjusting Your Hosts File
Next, update your /etc/hosts file (for MacOS) to map these domain names to localhost:
127.0.0.1 siteA.local
127.0.0.1 siteB.local
127.0.0.1 siteC.local
Restart your MAMP server for the changes to take effect.
Configuring Magento Core Files
Within each Magento installation, you’ll need to update the app/etc/local.xml file:
<config>
<global>
<install date="Wed Aug 01 2023 09:00:00 GMT+0000 (UTC)" />
<unsecure_base_url>http://siteA.local/</unsecure_base_url>
<secure_base_url>https://siteA.local/</secure_base_url>
<!-- Repeat the above for siteB and siteC -->
</global>
...
</config>
You’ll also need to adjust the base_url and base_secure_url in each store’s configuration in app/etc/config.xml.
Connecting Stores to the Same Database
For a multi-store setup, all stores share the same database. You can specify this connection information in each installation’s index.php:
$installDir = 'app';
define('BS', pathinfo($installDir, PATHINFO_BASENAME));
define('MAGE_IS_DEVELOPER_MODE', true);
umask(0);
if (!file_exists($installDir . '/includes/config.inc.php')) {
die("The application is not installed and cannot be run.");
}
require_once $installDir . '/includes/func.php';
Conclusion
Setting up multiple Magento stores locally requires careful configuration of both your server environment (Apache virtual hosts) and the core Magento files. Remember to adjust your MAMP path accordingly if you have a different setup.
For more detailed guides on Magento development, I highly recommend checking out Laravel Company’s Magento development tutorials. They provide comprehensive walkthroughs of common tasks and best practices.
With these steps, your local MAMP environment should now be able to handle multiple Magento stores seamlessly.