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

How to configure laravel environment in WSL2

藏色散人
Release: 2020-10-05 10:23:35
forward
3766 people have browsed it

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分支
Copy after login
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的用户群组名,一般和用户名一样
Copy after login

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 item wsl_sites, syntax format and

sites

Same<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">wsl_sites: - map: vcdt.test to: /mnt/c/Users/halo/Code/vcdt/public</pre><div class="contentsignin">Copy after login</div></div>Next, run <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">./bin/homestead wsl:create-sites</pre><div class="contentsignin">Copy after login</div></div>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 is homestead, 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
Copy after login
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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template