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– Akif2019-02-23 09:38:27 +00:00Commented Feb 23, 2019 at 9:38
-
I mean this - docs.microsoft.com/en-us/windows/wsl/faqVivek Kumar– Vivek Kumar2019-02-23 13:58:18 +00:00Commented Feb 23, 2019 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– kovinet2020-09-08 05:45:53 +00:00Commented Sep 8, 2020 at 5: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– Vivek Kumar2020-09-08 07:46:16 +00:00Commented Sep 8, 2020 at 7:46
1 Answer
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.
-
I've my code inside Windows system and I created symlink as you guided. But It is not generating static content and showing static contentBhavin Shah– Bhavin Shah2019-04-22 00:17:32 +00:00Commented Apr 22, 2019 at 0: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– Vivek Kumar2019-04-22 05:39:02 +00:00Commented Apr 22, 2019 at 5: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– Bhavin Shah2019-04-22 22:36:47 +00:00Commented Apr 22, 2019 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– Vivek Kumar2019-04-23 02:33:22 +00:00Commented Apr 23, 2019 at 2:33
-
I will try it when I have some time and update you.Vivek Kumar– Vivek Kumar2019-04-23 02:34:11 +00:00Commented Apr 23, 2019 at 2:34
