Within just one single instance of Magento, we can have multiple websites, stores, and storeviews operating on the same Magento backend. This allows limitless flexibility for your eCommerce operations.
In today’s tutorial, We are going to see how we can do multiple domain setups for our Magento project in the DDEV Local environment.
DDEV is an open-source tool for launching local web development environments in minutes. It supports PHP, Node.js, and Python, etc languages.
While developing in the local environment, creating virtual hosts, adding hosts and many more configurations was time-consuming and complex.
But using DDEV you can add and link multiple domains with your Magento 2 projects in a few easy steps.
So, let’s start by following the below the quick steps.
Step 1: Add Additional Domain
To start with a multi-website setup you will be required to add a new domain to your ddev project for your second website.
Suppose, I have firstdomain.ddev.site as my main domain for the main website and I want to link a new domain to my second seconddomain.ddev.site domain.
I will need to define my second domain to the additional_hostnames inside the .ddev/config.yaml file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
name: firstdomain type: magento2 docroot: pub php_version: "7.4" webserver_type: nginx-fpm xdebug_enabled: false additional_hostnames: [seconddomain] additional_fqdns: [] database: type: mariadb version: "10.4" use_dns_when_possible: true composer_version: "2" web_environment: [] webimage_extra_packages: [php7.4-imap] |
So, to reflect changes we need to restart our project using the below command.
1 |
ddev restart |
After restart, if you perform ddev describe, you will see the new domain added to the project followed by seconddomain.ddev.site
Step 2: Link the domain with the second website
Now, as our new domain is configured, we need to link it with our second website store.
To do this, you have to add the below code at the start of the .ddev/nginx_full/nginx-site.conf file
1 2 3 |
map $http_host $MAGE_RUN_CODE { secondwebsite.ddev.site store_view_code; } |
Note : you have to remove #ddev-generated line from this file in order to allow your customization.
Step 3: Restart the project to reflect nginx configurations
1 |
ddev restart |
By following the above steps, you will be able to access your second store using seconddomain.ddev.site
If you like this tutorial, Please share it with your team members. 🙂
Don’t forget to check the below ddev related tutorials :
DDEV Docker: How to install additional PHP extensions in the DDEV project?
Comments
If I want use website code, how should I do ?
Author
Please follow : https://gist.github.com/jigarkkarangiya/59195e475ce73dc061c1f104280c48fc