Is there some good guide on how to use Linux subsystem provided with Windows 10 to set up and run Magento 2?
-
What do you mean with "subsystem"? A virtual machine? – Akif Feb 23 '19 at 09:38
-
I mean this - https://docs.microsoft.com/en-us/windows/wsl/faq – Vivek Kumar Feb 23 '19 at 13:58
-
Basically after you have one of the Linux distributions installed in WSL 2 all the rest is same as if running Magento directly on Linux. You can access the files trough \wsl$..\ path path from Windows host. I am developing Magento 2 like this, the only issue I have is slow sync of file changes in WSL in PhpStom. – kovinet Sep 08 '20 at 05:45
-
Yes. But if you want to access an existing project you can use symlinking to /var/www/html as I've mentioned. – Vivek Kumar Sep 08 '20 at 07:46
1 Answers
Introduction:
The Windows Subsystem for Linux (WSL) is a new Windows 10 feature that enables you to run native Linux command-line tools directly on Windows, alongside your traditional Windows desktop and modern store apps.
The Windows Subsystem for Linux lets developers run GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a virtual machine.
You can:
- Choose your favorite GNU/Linux distributions from the Windows Store.
- Run common command-line free software such as grep, sed, awk, or other ELF-64 binaries. Run Bash shell scripts and GNU/Linux command-line applications including:
- Tools: vim, emacs, tmux
- Languages: PHP, Javascript/node.js, Ruby, Python, C/C++, C# & F#, Rust, Go, etc.
- Services: sshd, MySQL, Apache, lighttpd Install additional software using own GNU/Linux distribution package manager.
- Invoke Windows applications using a Unix-like command-line shell.
- Invoke GNU/Linux applications on Windows.
Installation:
- Enable developer mode from settings.
- Open powershell/cmd as admin and enable WSL using following command
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
You can also enable it from window features in GUI.
- Restart your system.
- Install distro of your choice from the windows store. (Just search for eg. Ubuntu and install).
- Access WSL using
bashcommand on cmd. - It will ask you to set username and password for your linux user.
- Check your distro using the following command ;
lsb_release -a
- Install apache using the following command;
sudo apt-get install apache2
- Start apache using the following command;
sudo service apache2 start
Access localhost to see if apache has been started successfully. Just open up the browser of your choice and type 'localhost'.
Install mysql using following command ;
sudo apt-get install mysql-server
- Start mysql using the following command ;
sudo service mysql start
- Access mysql to make sure it is running properly
mysql -uroot -p
Use exit/quit command to exit mysql.
- Install PHP using the following command
sudo apt-get install php7.2
You can install php version of your choice by just mentioning the version.
- Check if PHP has been installed using the following command;
php -v
- Check if you have all the modules needed by placing
index.phphavingphpinfo()at/var/www/htmland accessinglocalhost/index.php - Install composer using following command;
curl -sS https://getcomposer.org/installer -o composer-setup.php
If you do not have curl, install it using sudo apt-get install curl
- Make symlink of your Windows Magento project folder/ from where you want to access Magento files in /var/www/html using ;
sudo ln -s /mnt/c/projects/magento23 /var/www/html/magento23
Note that all the windows filesystem can be found mounted in /mnt folder.
- cd into your symlinked folder and install Magento using composer.
In my opinion, the WSL way of using Magento in windows is much faster than native windows and much more hassle-free than installing a virtual machine and dealing with its problems. You also have direct access to all project files so you can use your preferred editor for coding.
Note : Currently I have to start apache and mysql server after every restart but I will update if I can get it added to systemctl boot time.
- 5,115
- 2
- 24
- 50
-
I've my code inside Windows system and I created symlink as you guided. But It is not generating static content and showing static content – Bhavin Shah Apr 22 '19 at 00:17
-
you have created symlink for whole Magento folder in /var/www/html/ right? It should be working if you've done that. – Vivek Kumar Apr 22 '19 at 05:39
-
I want to setup magento 2 pwa studio. Can share guide how to do that? I tried magento 2 official guide but it is not working. – Bhavin Shah Apr 22 '19 at 22:36
-
I have not tried to setup PWA studio in subsystem but I was able to set it up fine on my Linux machine using the same instructions.. – Vivek Kumar Apr 23 '19 at 02:33
-
-
That would be great help Vivek. thank you so much. Also, create a video tutorial when you are working if possible. Thank you – Bhavin Shah Apr 23 '19 at 18:43
-
Can you please check this error? https://magento.stackexchange.com/questions/271144/pwa-studio-yarn-build-error – Bhavin Shah Apr 23 '19 at 18:52
-
Magento not loading static files might be a separate issue that doesn't have to do with loading it under WSL, I had the same under Linux Mint. See also https://magento.stackexchange.com/questions/97209/magento-2-css-and-javascript-not-loading-from-correct-folder – bdbdbd Jan 13 '20 at 19:56
-
I have set up WSL ubuntu with Magento 2.3 but magneto is very slow. cache is enabled and Magento is in default mode. My system is core i5 with 8 GB RAM and SSD. – ishaq Feb 26 '21 at 12:59
-
You can look into https://medium.com/@leandrocrs/speeding-up-wsl-i-o-up-than-5x-fast-saving-a-lot-of-battery-life-cpu-usage-c3537dd03c74 – Vivek Kumar Feb 26 '21 at 13:13
