How to setup Multiple Domains in a Multi-Store Setup - Magento 2 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
out the box magento is capable of running multiple websites from a single installation including the ability to assign each website with their own domain in this video i'll be showing you how to configure apache virtual host to connect to your multi-store websites after this short message digital startup can now be found on twitch under the science and technology category this is where you'll find me streaming behind the scenes content such as informal discussions research for upcoming videos video editing and youtube preparation you'll also catch me learning javascript most weekends so if you enjoy informal behind-the-scenes content follow me on twitch.tv slash digital startup before we begin this tutorial assumes that you already have magento 2 up and running with apache on ubuntu you'll also be able to copy and paste any of the commands i used directly from the article linked in the video description below i'd also like to thank kaz and mona for helping me to put this video together during my twitch live stream last week before recording this video i set up two new subdomains with my domain provider both pointing to my sandbox server where magento is installed note even though i have set up some domains in this example full domains would work too before diving into the apache configuration i want to show you the absolute basic settings that need changing in order for this to work i will not be showing products customer store setup or anything like that so having logged into my magento backend if i navigate to stores all stores you can see that i've set up two additional websites each with their own store and store view when setting up new stores stores and store views i like to give them smart easily identifiable names however in this example i have left the main website details alone to indicate to you that i have not touched them otherwise i probably would have re-labeled main website store to main store default store view to english and i would have changed the codes from main website store to main store and defaults to main english if you haven't done this yet you have to create websites before store and store before store view otherwise you won't be able to link them now if we go into stores configuration web you'll also see that i've updated the base urls for the two new websites by clicking the scope drop down and clicking on one website you can see that i've updated the default value of the base url the base link url the secure base url and the secure base link url to include the one dot subdomain that i set up and then if we switch the scope to two websites you'll see that i've done the same thing there as well adding the two dots into the domain for base base link secure base and secure base link finally i also changed the theme and logo for each of the three stores purely to indicate that we are in fact loading different websites during the testing phase i did this under content design configuration and updated the parents records to each website and just to clarify the parents record is the line where all three columns have a value so right now i'm logged into the web server as the super user so the first thing to do is to navigate to the apache configuration folder by entering cd space slash ptc apache2 sites dash enabled and then we can list the contents of the folder by using ls space dash la you'll see at the very least two files one called zero zero zero dash default dot conf and the other being defaults dash ssl dot conf in my example i have an extra file called zero zero zero dash default dash le ssl.conf this is only because i already have a let's encrypt ssl certificate installed for the main websites rather than create new apache configuration files from scratch we can simply copy the default file to create new ones from it as i alluded to earlier i like to name things so they're obvious to me so i'll be naming my new configuration files as one dot digital startup tutorials dot code uk dot conf and then two dot digital startup tutorials dot credit uk dot conf i admit those names appear quite long but they're much easier to identify when you have about 10 configuration files sitting there thank me later so in order to copy the original and paste it with the new names type sudo space cp which stands for copy space zero zero zero dash default dot conf which is the file we want to copy and space one dot digital startup tutorials dot credit uk dot conf which is the name we want to assign the copied file and the same again sudo space cp space zero zero zero dash default dot conf space two dot digital startup tutorials dot co decay dot conf now if we list the folder content again with ls space dash la will see the two new files in each of the files we just created we need to add four lines to get apache virtual hosts working with magento multi-domain open the first configuration file with a nano text editor by typing sudo space nano space one dot digital startup tutorials dot code uk dot conf after the line containing document root slash var slash www slash html copy and paste the following four lines out of the four lines you only need to edit the first three the server name which will be your domain url the server alias which again will be your domain url and then the set end mage run code which will be your web site code as you remember from earlier i called the code for my website one so therefore i've got one once updated save the changes by pressing control x to exit y to save and enter to confirm now let's do that again with our two websites open the configuration file by typing sudo space nano space to digital startup tutorials dot co uk dot conf and then add the four lines again after the document slash root slash www slash html line and again as you can see my server name and server alias are my domain urls and the set end major and code is the code that i signed this website back when we set it up in magento which was two and when it's finished save your changes by pressing control x to exit swipe save and enter to confirm now it's not just enough to create the configuration files but we need to enable them to to do this run the following sudo space a2 en site space 1 dot digital startup tutorials dot co uk.conf and then sudo space a2 en site space 2 dot digital startup tutorials dot co dot uk dot conf followed by the restart of apache so here i'd put sudo space system ctl space restart space apache 2 you could also use reload as well so long as you haven't made any syntax errors which you shouldn't have done if you simply copied and pasted you won't see any error messages you can ignore this next step if you aren't running a let's encrypt ssl certificates so even if you have a let's encrypt ssl certificate setup on your original domain you should run the let's encrypt script again to ensure that the setting you just changed also apply to your apache ssl configurations otherwise you'll run into an issue where none of the things we changed will work when the customer connects over https so to regenerate your ssl certificates and apache ssl configuration files enter sudo space search bot space dash dash apache space dash d followed by your domain name or urls that you want to register so again for every time you want to add a domain name you'll put a space dash d in front of it like i have here once you finish putting the line together and you hit enter the script will run at the first prompt hit e to expand and at the second prompt enter 1 to not force redirection now again in this next step if you're not running an ssl certificate ignore it if you are running an ssl certificate through something like digital cert or global sign where you have to set up your own configuration files this is just a friendly reminder to remind you that once you create your ssl certificates to make sure that you add those four lines we added earlier to your apache ssl configuration files okay so now that the apache stuff is out the way we need to switch to the magento user so let's put in su space magento followed by the magento user's password and then switch to the magento directory with cd space slash var slash www slash html and now let's start by redeploying static contents and we do that by entering bin slash magento space setup colon static dash content colon deploy space en underscore us space en underscore gb space dash f now before you go ahead and copy and paste that my store contains both the us and gb locales so change yours accordingly to your own setup now let that run for a couple of minutes so i'm going to skip forward because it will take a moment and then once it's done we want to clear the cache with bin slash magento space cache colon clean hit enter and wait for that to run and then as soon as that's finished running it's time to test our three domain names so first things first let's test out the main domain name just make sure it's working so in that case that's going to be digital startup tutorials.credit uk for me and we'll let that load it will take a moment because we just cleared the cache and we deployed static content so everything's going to be slow on the first load and there we go so as you can see this is the main website confirmed by the logo that i changed earlier and then we can try our next domain name which is one dot digital startup tutorials that cut it okay and let's wait for that to load and there we go we can see that one's loading correctly confirmed by the logo that i changed earlier and finally we will load up two dot digital startup tutorials dot code uk and see if that loads correctly and there we go we can see that that's loaded correctly as well that's pretty much how you do it like i said i'm not going to be going over any of the configuration for multi-store setups that might be content i run into in the future but that's not what this is a video is all about so again remember you can copy and paste everything it from the article and the link to that is in the video description below you'll also find me on twitch as well for the behind the scenes contents until next time take care
Info
Channel: Digital Startup
Views: 4,917
Rating: undefined out of 5
Keywords: magento, starting an online store, build a magento store, how to, tutorial, ecommerce, web development, digitalstartup, magento 2 beginner tutorial, magento 2
Id: 0aU5viBd1AE
Channel Id: undefined
Length: 12min 55sec (775 seconds)
Published: Thu Oct 01 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.