Home>Article>PHP Framework> How to configure laravel environment in WSL2

How to configure laravel environment in WSL2

藏色散人
藏色散人 forward
2020-10-05 10:23:35 3614browse

The following tutorial column will introduce to you how to configure the laravel environment in WSL2. I hope it will be helpful to friends in need!

Reference: https://github.com/laravel/homestead/issues/1484How to configure laravel environment in WSL2

vagrant virtualbox on windows The version will have strange errors after opening wsl2. . . The hyperv version cannot be downloaded at all. It just so happens that the maintainer of homestead recently created a

one-click installation script

for wsl2. After trying it out, it seems to be okay. Here are the steps.

Configure the environment

First download the homestead repo
git clone https://github.com/laravel/homestead cd homestead git checkout 20.04 #切换至20.04分支
and then run the installation script.

sudo -E ./bin/wsl-init What is your WSL user name? # 输入wsl的用户名,软件将安装到该用户名下 What is your WSL user group? (Same as username if you're unsure) # 输入wsl的用户群组名,一般和用户名一样

The script will automatically install and configure the required software environments such as php, mysql, nginx, etc. on wsl.

Mount the website

After the installation is complete, edit the Homestead.yaml file and add the new configuration itemwsl_sites, syntax format and

sites

Same

wsl_sites: - map: vcdt.test to: /mnt/c/Users/halo/Code/vcdt/public
Next, run
./bin/homestead wsl:create-sites
The configuration file will be automatically written to nginx. At this time, visit

127.0.0.1

(or edit the following under windows After accessing the domain name directly after the hosts file), you should be able to see that the website is online. If you can't see it, you can refer to

this article

and get the IP of the wsl2 virtual machine before trying again.Some problems encountered

mysql password

Looking at the script, I found that the configuration is the same as the homestead virtual machine, the user name It ishomestead, and the password is

secret

.The website response speed is very slow

I checked this and it seems that The problem with wsl2 file io is that the speed of accessing the windows disk is extremely slow, and there is no solution for the time being. You can see

Major performance (I/O?) issue in /mnt/* and in ~ (home)

windows local directory:

How to configure laravel environment in WSL2

How to configure laravel environment in WSL2The website cannot be loaded after restarting

After checking, it seems that the wsl2 service will not start automatically. . . This can only be done manually, or by writing
sudo service nginx restart sudo service php7.4-fpm restart sudo service mysql restart
in .bashrc

The above is the detailed content of How to configure laravel environment in WSL2. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete