(WSL) Ubuntu 快速搭建 PHP 开发环境
简介
Windows Subsystem for Linux(简称WSL)是一个在Windows 10上能够运行原生Linux二进制可执行文件(ELF格式)的兼容层。有了WSL你就能在Windows下愉快的使用Linux了。
一、安装
1.1 管理员Windows PowerShell运行
右键 开始菜单 -> Windows PowerShell(管理员) ,执行命令:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
1.2 或者
控制面板->程序和功能->启用或关闭Windows功能->勾选 适用于Linux的Windows子系统
2 重启电脑
3 打开 应用商城
搜索 “Linux” ,选择安装一个或多个Linux系统
或者
3.1 下载相应Linux安装包
docs.microsoft.com/zh-cn/windows/w...
3.2 管理员打开Windows PowerShell 运行以下命令(下载文件相应的目录)
Add-AppxPackage .\Ubuntu_2004.2020.424.0_x64.appx
4 初始化用户名和密码(示例:Ubuntu)
Installing, this may take a few minutes...
Enter new UNIX username:(用户名)
New password:(密码)
Retype new password:(确认密码)
#输入下面命令,设置ROOT密码
$ sudo passwd
5 完成
二、快速搭建PHP环境(已更新为Ubuntu 20.04)
说明:因为在 Windows 系统启动后运行(WSL)Ubuntu,Ubuntu不会自动启动服务(大部分),所以需要手动开启所需服务(如 Php、Mysql、ssh 等),推荐使用 alias 管理启动。
Github 推荐链接:
github.com/zoang/wsl-ubuntu
# 进入root 用户,执行下面命令即可(近期RAW访问异常,请Clone后,进入SRC目录,运行 ./install.sh 进行安装):
# git clone https://github.com/zoang/wsl-ubuntu.git
wget -qO- https://raw.githubusercontent.com/zoang/wsl-ubuntu/master/download.sh - | bash
本Shell自动设置时区,替换成阿里源,安装PHP及依赖,更新Node\Npm等,设置了一个快捷命令 wsl 来启动所需服务。
三、要点记录
这里会记录各类问题及要点,也可把你遇到的问题反馈给我,不定时更新。
NGINX记录 *
1.在/etc/nginx/nginx.conf http{}内加入下面代码(已在install.sh中自动添加【已修复】):
http{
#其他配置不用修改,加入以下代码,解决Unix Socket BUG
fastcgi_buffering off;
}
其他
1.Ubuntu目录与Windows的映射
# C盘
/mnt/c
# D盘
/mnt/d
# 类推
2.host说明
直接修改 Windows host 即可映射
#直接修改 C:\Windows\System32\drivers\etc\hosts
127.0.0.1 larabbs.test
3.重启 Windows 10 子系统(WSL) ubuntu
直接关闭窗口,或者 Windows PowerShell(管理员) ,执行命令:
#Windows PowerShell(管理员模式)
net stop LxssManager
net start LxssManager
4.配置git账号关联
# root用户下运行
ssh-keygen -t rsa -C "youremail@example.com"
ssh-add ~/.ssh/id_rsa
# 如果提示:Could not open a connection to your authentication agent.
# 运行下面命令()
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa
复制id_rsa.pub内容到GIT settings > SSH and GPG keys
新建 New SSH key
# 验证下,是否正确
ssh -T git@github.com
本作品采用《CC 协议》,转载必须注明作者和本文链接
刚好重装了系统,整起来 :confused:
wsl2 环境 还需要加 fastcgi_buffering off 吗