开启子系统
1.先去Win10的设置》应用》程序和功能开启适用于Linux的Windows子系统并重启
2.微软商店搜索WSL并下载Ubuntu18.04LTS版本
安装系统(左下角菜单打开Ubuntu18)
注意:初始化一定要设置用户名和密码
设置root密码
sudo passwd root
切换软件源镜像(阿里云Ubuntu镜像地址)
#首先先备份我们系统自带的软件源 输入以下命令
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
# vim 编辑 sources.list
sudo vim /etc/apt/sources.list
# 将之前的镜像地址删除并将阿里云的镜像地址复制进去后保存文件
# ubuntu 16.04 配置
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe
# ubuntu 18.04(bionic) 配置
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
# ubuntu 20.04(focal) 配置
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
# 然后我们更新软件软件列表 运行如下命令
sudo apt-get update
安装开发软件
1.安装php
# 首先我们需要添加PHP的PPA软件源运行如下命令:
sudo add-apt-repository ppa:ondrej/php
# 安装PHP7.4及相关扩展 运行如下命令:
sudo apt-get install php7.4 php7.4-fpm php7.4-bcmath php7.4-curl php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-xml php7.4-zip php-redis
# 安装成功后可运行如下命令验证安装
php -v //查看PHP版本
php -m //查看扩展安装列表
2.安装Composer
# 下载composer.phar:
wget https://getcomposer.org/composer.phar
# 重命名composer.phar为composer
mv composer.phar composer
# 增加可执行权限
sudo chmod +x composer
# 设置为全局可执行
sudo mv composer /usr/local/bin
3.安装SSH服务端
# 执行如下安装命令
sudo apt-get install openssh-server
# 配置SSH服务端
sudo vim /etc/ssh/sshd_config
# 配置修改为如下图(Port的值可以自定义自己选择你要用的端口号)
# 修改完配置 wd保存,然后终端执行 (sudo service restart)
sudo service restart
# 这时候如果启动ssh可能会失败(提示:sshd:unrecognized service)可执行如下命令
sudo /etc/init.d/ssh restart //(或sudo /etc/init.d/ssh start)
# 其他ssh管理命令
sudo service ssh status
sudo service ssh start
sudo service ssh stop
sudo service ssh restart
至此,就可以连接ssh了
linux与window主系统文件互相访问
WSL和Windows主系统之间的文件系统是可以互相访问的。
如果在WSL中访问Windows系统的文件,可在根目录下/mnt/看到对应Windows盘符字母的文件夹,通过这些文件夹即可访问Windows的文件系统。
如果在Windows系统中访问WSL的文件,可在Windows系统中找到已安装Linux发行版的应用数据文件夹,所有Linux系统的数据都在那个文件夹(通过应用商店安装的Linux发行版本质上也是一个应用)。Linux发行版的数据文件夹在C:\Users{你的用户名}\AppData\Local\Packages{Linux发行版包名}\LocalState\rootfs路径内,在rootfs文件夹内我们会看到在WSL中的根目录。
需要注意的是,在Windows下对WSL文件修改可能会造成权限错误
注意事项
配置无法编辑,无法保存,无权限问题,可su root切换到root用户再操作