I have been hard at work on a way to effectively work on Magento within Windows 10. Microsoft has come a long way in their quest to be more linux/unix-friendly, however nothing beats the ease of installing linux/unix-native applications in a native environment. My quest brought me to Hyper-V, a Windows 10 Professional Virtual machine application I have used with all manner of Windows virtual machines. This article covers how you can have Magento up and running on Ubuntu within your Windows 10 desktop in roughly an hour.
Now let's stop and fix something important. One of the biggest issues with the Ubuntu VM out of the box is that the hard drive space allotted for the expandable drive is woefully small at 11GB. If you don't fix this now, once you begin to install Magento, the VM will run out of space. Let's fix that.
Important Note: The available partition space for the VM will now be 30GB. However, Ubuntu will still assume it is using the default physical space assigned to it with Windows' VM settings since we haven't told Ubuntu it can use the new space. We'll fix that later with an app called gparted.
In the Hyper-V Manager, right-click the Ubuntu VM and select 'Connect'. The VM will boot up and begin configuration. Configure as you desire, but the most important detail with configuration is to remember: do not select 'Connect automatically' on the screen where you enter login credentials during configuration. Doing so will cause the VM to refuse to boot while in Enhanced Boot mode (the default mode).
Allow Ubuntu to reboot and login using your Ubuntu account credentials to the entirely out-of-place xrdp session panel. Once the OS successfully boots to the desktop, it would be a good idea to create a Hyper-V checkpoint in the event something goes wrong so you can restore and start again.
A quick note about Hyper-V VM checkpoints... this creates an extra file that will be used by the VM next to the *.vhdx in your Windows file system that can grow to a size equal to your *.vhdx file. If you are strapped for space, use them sparingly.
Once at the desktop, let the Ubuntu install update repository sources. Super important. The prompt to do so should appear within a couple of minutes. Enter your password and download updates. Let the updates install and reboot Ubuntu to be sure everything is installed correctly.
Let's go ahead and take care of that partition issue before we go much farther. Install gparted from the Software application (access via search from 'Activities'). if it is not available, you can install it manually. Use gparted to expand the primary partition to fill the entire available space.
At this point, install any IDEs you use for code editing using the software center or any manual terminal install instructions available for your chosen IDE. Ubuntu is Debian-based, so you can use most environment-agnostic Debian install instructions as well as Debian standalone installers.
We're on the home stretch now! Next up, we'll install Docker CE, get our containers from DockerHub, and install Magento 2.x.
We're going to use Docker to handle our Magento containers so we don't have to go through the process of getting php, sql, etc. installed. Docker also containerizes the services, which allows you to experiment with configurations if you're feeling saucy.
Digital Ocean has a great tutorial to get you up and running with Docker. This is written for 18.04, but it also works with 19.04. I recommend using the Alternate Version if you want to use this guide. One thing that tripped me up in subsequent steps was the lack of `docker-compose` availability. You need to install this separately and here is a guide for that.
We're going to be using Docker Magento by Mark Shust for our Docker experience. This is well documented, feature-rich, and very easy to use for even the novice Magento developer. Please take a moment to peruse the repository documentation `readme.md` file.
Ready? Open terminal. Create a folder called `repos` (or whatever you call your repo storage) within the user space. Create a folder called `magento` within that. In terminal, use `cd repos/magento'. Either download a zip of the Docker Magento repository or use your Github.com account and git to download the repo to the `magento` directory. This is where you will need to use your GitHub.com username/password or a Personal Access Token if you have Two-Factor authentication enabled.
Now that we have the docker *.yml (yaah-mail) files, we can pull our containers. Ensure docker is running using `docker info`. If not, start docker using `docker restart`. Per the repo's DockerHub page, use `docker pull markoshust/magento-nginx` to retrieve the Magento containers for use.If you ran this command from the `magento' repo directory, it should ready the *.yml files there and grab the containers! You should see quite a bit of activity if this works as expected.
Once the containers are downloaded and the prompt is available, start them using `'docker-container start`.
Now that we have our repo and containers, we're ready to install Magento! Run the following command at the termianl prompt in `repos/magento`, per documentation in the repo:
`curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/onelinesetup | bash -s -- magento2.test 2.3.2`
Let's break down what is happening here beyond the URL curl call:
Once this completes, open your browser to the URL chosen for the install and Magento should load without issue!
I hope you found this guide useful and now have a working Ubuntu VM with a working, fast Magento 2 installation. It took me a few attempts to get my environment right where I want it to be, but I am now able to operate within Windows 10 and preview my changes freely within Windows 10.
Feel free to let me know if you have any questions!