windows10 安装wsl子系统 ubuntu进行php开发与调试 | 您所在的位置:网站首页 › 搭建php开发环境分析系统 › windows10 安装wsl子系统 ubuntu进行php开发与调试 |
win10安装wsl
视频教程: 从Build 14393版本开始,Windows10已经原生支持Linux,下面讲解一下如何使用wsl进行本地php开发与调试. 一、启用“适用于Linux的Windows子系统(WSL)”通过Win10任务栏中的Cortana搜索框搜索打开“启用或关闭Windows功能”,向下滚动列表,即可看到“适用于Linux的Windows子系统(Beta)”项。 然后进入“设置 - 更新和安全 - 针对开发人员”设置页面,选中“开发人员模式”。如图: 右键点击Win10开始按钮,选择“Windows PowerShell(管理员)”以管理员身份运行Windows PowerShell。输入并回车运行以下命令: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux 四、下载并安装Ubuntu(可通过Microsoft Store获取)打开应用商店 (Microsoft Store),搜索linux 首次启动Ubuntu,会有一个安装过程,需要设置用户名和密码。如图: 系统默认的apt源是国外的,下载软件速度慢,python的pip源也很慢,我们都换成阿里云的源。 更换apt源: cd /etc/apt/ sudo cp sources.list sources.list.bak && sudo vim sources.list删除其中所有内容,替换成: deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse deb http://archive.canonical.com/ubuntu/ xenial partner deb http://extras.ubuntu.com/ubuntu/ xenial main然后执行 sudo apt update sudo apt upgrade 修改pip源:创建pip配置文件: mkdir ~/.pip && vi ~/.pip/pip.conf在打开的vim中输入下文并保存: [global] trusted-host=mirrors.aliyun.com index-url=http://mirrors.aliyun.com/pypi/simple/ 五、安装php服务器环境 宝塔面板 wget -O install.sh http://download.bt.cn/install/install-ubuntu.sh && sudo bash install.sh按提示进行操作,默认回车即可.安装成功如下图: 为了完全模拟服务器环境,需要创建host以及服务器主机. 首先创建本地host.使用文本编辑器打开本地hosts文件,路径在:C:\Windows\System32\drivers\etc\HOSTS在最后一行,添加一个新的host 127.0.0.1 test.local保存后关闭即可. 然后进入宝塔管理面板的"网站"管理,点击"添加站点"创建新网站. 在域名输入框中输入和上面的host一致的主机名称: test.local其他选项可默认.点击"提交"按钮后,本地的主机环境就已经部署好了.现在打开浏览器,输入"http://test.local"看看效果吧! 为了便于开发,我们可以把网站目录设为实际开发项目的路径,比如 c:\web\test.这样,我们在phpstorm中修改项目文件后,网站即可实现实时更新. 我们再次进入宝塔管理面板的"网站"管理,找到刚刚创建的网站,点击设置.左侧菜单中找到"网站目录",选择"/mnt/c/web/test",然后保存即可.其中"/mnt/c"即代表 windows的c盘,依此类推 d盘根目录即为"/mnt/d". 现在我们就可以使用phpstorm直接修改网站文件,并实时预览效果了! |
CopyRight 2018-2019 实验室设备网 版权所有 |