Tutorial—Set up multiple websites with Apache
Set values in an entry point script
If necessary, copy the existing index.php
entry point script for your website or store view and add to it the following:
-
You’re working on a development machine (laptop, virtual machine, and so on)
Additional tasks might be required to deploy multiple websites in a hosted environment; check with your hosting provider for more information.
Additional tasks are required to set up Adobe Commerce on cloud infrastructure. After you complete the tasks discussed in this topic, see Set up multiple Adobe Commerce on cloud infrastructure websites or stores.
-
You use one virtual host per website; the virtual host configuration file is
/etc/httpd/httpd.conf
Different versions of Apache on different operating systems set up virtual hosts differently. Consult the Apache documentation or a network administrator if you’re not sure how to set up a virtual host.
- The Magento software is installed in
/var/www/html/magento2
-
You have two websites other than the default:
french.mysite.mg
with website codefrench
and store view codefr
german.mysite.mg
with website codegerman
and store view codede
Roadmap for setting up multiple websites with Apache
Setting up multiple stores consists of the following tasks:
- Set up websites, stores, and store views in the Admin.
- Create one Apache virtual host per Magento 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:
-
As a user with
root
privileges, open the virtual host configuration file in a text editor.For example, open
/etc/httpd/conf/httpd.conf
- Locate the section starting with
<VirtualHost *:80>
. -
Create the following virtual hosts after any existing virtual hosts:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<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>
- Save your changes to
httpd.conf
and exit the text editor. -
Restart Apache:
- CentOS:
service httpd restart
- Ubuntu:
service apache2 restart
- CentOS:
Verify your site
Unless you have DNS set up for your stores’ URLs, you must add a static route to the host in your hosts
file:
- Locate your operating system’s
hosts
file. -
Add the static route in the format:
1 2
<ip address> french.mysite.mg <ip address> german.mysite.mg
-
Go to one of the following URLs in your browser:
1 2 3
http://mysite.mg/admin http://french.mysite.mg/frenchstoreview http://german.mysite.mg/germanstoreview
You’re done!
- Additional tasks might be required to deploy multiple websites in a hosted environment; check with your hosting provider for more information.
- Additional tasks are required to set up Adobe Commerce on cloud infrastructure; for more information, see Set up multiple Cloud websites or stores
Troubleshooting
- If your French and German sites return 404s but your Admin loads, make sure you completed Step 6: Add the store code to the base URL.
- If all URLs return 404s, make sure you restarted your web server.
- If the Admin doesn’t function properly, make sure you set up your virtual hosts properly.