此前一直使用macOS,由于mac有着良好的开发生态,以及软件生态.所以它是部署开发环境是极佳的操作系统.最近由于某些原因需要使用Windows.众所周知,Windows在这方面远不如mac/Linux.虽然这是硬伤,但怎么样才能让他变得更好用一些.那么WSL功不可没.
首先在功能中打开WSL,然后去自带的商店中安装Ubuntu.不多详说.
Windows自带的powershell并不好用,即使是比cmd好用那么一点点,也是远不及mac的iTerm2的.但是我们可以选择使用cmder代替powershell.
设置默认wsl.
从终端开始, 使用zsh代替bash
bash
1sudo -i
2cd
3apt update && apt install zsh wget git curl python3 -y
4curl https://raw.githubusercontent.com/SorashitaInnei/zshconfig.zshrc/master/WSL.zshrc >> ./.zshrc
5source ./.zshrc
COPY
默认登录使用root身份,设置root密码 ```bash sudo passwd root ```
在开始按钮右键,在弹出菜单中打开 Power shell,执行下面命令,查看已安装的 Linux 子系统:
bash
1wslconfig /list
COPY
Power shell 设置 WSL Ubuntu 默认登陆用户root
bash
1ubuntu1804 config --default-user root
COPY
Power shell 执行下面命令,可查看 Ubuntu 命令的帮助信息:
bash
1ubuntu /?
COPY
执行下面命令,备份 apt 安装源:
bash
1sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
COPY
vim 编辑 sources.list :
bash
1sudo vim /etc/apt/sources.list
COPY
在 sources.list 中添加 apt 云源:
bash
1deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
2deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
3deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
4deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
5deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
6deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
7deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
8deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
9deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
10deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
COPY
### 配置ssh为下一步做准备 ```bash apt install openssl ssh -y ``` 修改默认端口 ```bash nano /etc/ssh/sshd_config ``` 把Port改成233, PermitRootLogin 改成yes,PasswordAuth改成yes,然后 ```bash service sshd restart ```
由于windows没有linux的某些特征,所以我们需要使用Linux的python来作为主要解释器.
bash
1apt install python3 python-dev -y
2where python3
COPY
打开pycharm pro,在这个选择WSL,输入一下用户密码
安装apache2,php7,mysql5.7
bash
1apt install apache2 php php-mysql php-fpm mysql-server php-xml
COPY
缺一不可. 我在这里遇到了500报错,utf报错是因为没装php-mysql和php-xml
默认路径修改成windows的路径会报403,这里除了要设置一下DocumentRoot,还要在apache2.conf
中设置一下
bash
1<Directory /mnt/c/Users/yiny/sites/>
2 Options Indexes FollowSymLinks
3 AllowOverride None
4 Require all granted
5</Directory>
COPY
这样就可以了