Windows上使用Vagrant打造Laravel Homestead可协同跨平台开发环境
2015-08-28 10:57
831 查看
Windows上使用Vagrant打造Laravel Homestead可协同跨平台开发环境
By wsgzao发表于 2015-07-18
![](http://i.v2ex.co/vyf30F6d.png)
前言
大家对VMware或者
VirtualBox一定不会陌生,虚拟化的好处自然深入人心,而现在我们可以通过
Vagrant搭建一套类似
Laravel Homestead完整开发环境,这样极大的减少了架设开发环境的时间,同时还支持在
Windows/Mac/Linux不同平台上分享定制包,统一团队之间的开发环境提高工作效率,而
Docker的出现也让未来更值得期待。
用Vagrant为自己打造一个奇妙的跨平台开发环境
更新历史
2015年07月18日 - 初稿阅读原文 - http://wsgzao.github.io/post/vagrant/
扩展阅读
Vagrant - https://www.vagrantup.com/
Laravel Homestead - http://laravel.com/docs/5.1/homestead
在windows下进行linux开发:利用Vagrant+virtualbox - http://blog.star7th.com/2015/06/1538.html
在 Mac/win7 下上使用 Vagrant 打造本地开发环境 - http://segmentfault.com/a/1190000002645737
环境准备
Git(非必需)PHP(非必需)
Laravel(非必需)
Composer(非必需)
Vagrant
VirtualBox
如果大家有需要离线安装欢迎直接留言回复哈
安装git
1.下载GitHub for Windowshttps://windows.github.com/
安装php
建议大家尽量安装当前最新版本的 PHP1.下载PHP
http://windows.php.net/download/
2.解压目录
我的路径
D:\php
3.添加环境变量
右键计算机->高级系统设置->环境变量->系统变量->PATH
C:\ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\nodejs\;D:\php;C:\ProgramData\ComposerSetup\bin
4.设置php.ini
进入 PHP 安装目录(例如
D:\php)。找到
php.ini-development文件并复制一份到当前目录,重命名为
php.ini,修改以下配置
去掉
extension=php_mbstring.dll前面的分号(888 行左右)
去掉
extension=php_openssl.dll前面的分号(893 行左右)
去掉
extension_dir = "ext"前面的分号(736 行左右)
5.使环境变量生效
重启
explorer.exe
安装Laravel
1.下载Laravelhttp://www.golaravel.com/download/
2.解压目录
我的路径
D:\laravel-v5.1.4
3.启动Laravel
1 2 3 4 | d: cd laravel-v5.1.4 D:\laravel-v5.1.4>php artisan serve Laravel development server started on http://localhost:8000/ |
artisan的
serve命令还支持两个参数:
host设置主机地址
port设置 web server 监听的端口号
例如:
php artisan serve --port=8888
安装Composer
1.下载Composer-Setup.exe
https://getcomposer.org/doc/00-intro.md#installation-windows
2.配置Composer
1 2 3 4 | Loading composer repositories with package information Installing dependencies (including require-dev) SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed” |
cacert.pem到自定义路径
http://curl.haxx.se/docs/caextract.html
然后修改php.ini文件(1983行左右)
openssl.cafile=D:\php\verify\cacert.pem
3.测试Composer
1 2 3 4 | composer -V Composer version 1.0-dev (d79427f1a7b15e8f4d46ce8124a4d0c58ba1479c) 2015-07-04 1 1:22:58 |
安装Vagrant
1.下载Vagranthttps://www.vagrantup.com/downloads.html
2.离线下载虚拟镜像
https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.0.0/centos-6.6-x86_64.box
上面给出的是centos-6.6镜像下载链接,要下载其他镜像请访问官网
http://www.vagrantbox.es/
安装VirtualBox
BIOS里面开启CPU硬件虚拟化支持VT(Virtualization Technology)1.下载VirtualBox
https://www.virtualbox.org/wiki/Downloads
2.导入镜像
设置VirtualBox目录并拷贝镜像
centos-6.6-x86_64.box
E:\VirtualBox\centos-6.6-x86_64.box
3.命令初始化Vagrant
1 2 3 45 | #切换VirtualBox目录 e: cd .\VirtualBox #输入命令初始化 E:\VirtualBox> vagrant init centos6.6 A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant. #执行添加命令 E:\VirtualBox> vagrant box add centos6.6 centos-6.6-x86_64.box ==> box: Adding box 'centos6.6' (v0) for provider: box: Downloading: file://E:/VirtualBox/centos-6.6-x86_64.box box: Progress: 100% (Rate: 670M/s, Estimated time remaining: --:--:--) ==> box: Successfully added box 'centos6.6' (v0) for 'virtualbox'! #检查是否导入成功 E:\VirtualBox> vagrant box list centos6.6 (virtualbox, 0) |
Vagrant配置
详细配置文档可以参考官方手册 - https://docs.vagrantup.com/v2/启动Vagrant
通过Shell进入目录E:\VirtualBox后执行命令
vagrant up
顺利启动的完整过程如下所示
1 2 3 45 | E:\VirtualBox>vagrant upBringing machine 'default' up with 'virtualbox' provider... |
vagrant ssh连到虚拟机,需要使用
SecureCRT/Putty/Xshell等第三方工具进行连接。连接地址
127.0.0.1,端口
2222。登录的帐号
root的密码为
vagrant
1 2 3 45 | E:\VirtualBox> vagrant upBringing machine 'default' up with 'virtualbox' provider... |
Failed to open a session for the virtual machine,Unable to load R3 module C:\Program Files\Oracle\VirtualBox/VBoxDD.DLL (VBoxDD): GetLastError=1790 (VERR_UNRESOLVED_ERROR).,需要使用
UniversalThemePatcher还原未破解的
themeservice.dll themeui.dll uxtheme.dll文件
已经打包好的下载链接 - http://pan.baidu.com/s/1c0HGj2g
1 2 3 45 | ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection timeout. Retrying... default: Warning: Connection timeout. Retrying... default: Warning: Connection timeout. Retrying... |
default: Warning: Connection timeout. Retrying...,建议打编辑
Vagrantfile打开VirtualBox图形化界面
vb.gui = true进一步分析错误代码和原因。
导出box
通过Shell进入目录E:\VirtualBox后执行命令
1 2 3 45 | vagrant package vagrant package --output NAME --vagrantfile FILE #可选参数: --output NAME : (可选)设置通过NAME来指定输出的文件名 --vagrantfile FILE:(可选)可以将Vagrantfile直接封进box中 |
其它命令
vagrant up (启动虚拟机)vagrant halt (关闭虚拟机——对应就是关机)
vagrant suspend (暂停虚拟机——只是暂停,虚拟机内存等信息将以状态文件的方式保存在本地,可以执行恢复操作后继续使用)
vagrant resume (恢复虚拟机 —— 与前面的暂停相对应)
vagrant box remove centos6.6 (移除box,其中centos6.6是box名)
vagrant destroy (删除虚拟机,删除后在当前虚拟机所做进行的除开Vagrantfile中的配置都不会保留)
Laravel Homestead
细节部分可参考官方文档 - http://laravel.com/docs/5.1/homestead1.下载安装包
1 2 3 45 | vagrant box add laravel/homestead E:\Homestead>vagrant box add laravel/homestead ==> box: Loading metadata for box 'laravel/homestead' box: URL: https://atlas.hashicorp.com/laravel/homestead This box can work with multiple providers! The providers that it can work with are listed below. Please review the list and choose the provider you will be working with. 1) virtualbox 2) vmware_desktop Enter your choice: 1 ==> box: Adding box 'laravel/homestead' (v0.2.7) for provider: virtualbox box: Downloading: https://vagrantcloud.com/laravel/boxes/homestead/versions/0.2.7/providers/virtualbox.box box: Progress: 0% (Rate: 9d/s, Estimated time remaining: 0:05:30)11)) |
1 2 3 45 | #输入命令初始化 |
vagrant/vagrant,开始全新的
Laravel Homestead体验之旅吧。
相关文章推荐
- 实习小结十三:基于PHP ZF框架的文章管理模块
- vsftpd安装以及配置FTP虚拟用户实践
- PHP实现螺旋矩阵(螺旋数组)
- php 函数func_get_args()、func_get_arg()与func_num_args()之间的比较
- FTP命令字和响应码
- Java与PHP对于web开发的八大比较-------阿冬专栏
- php中二维数组排序问题方法详解
- PHP 单引号与双引号的区别
- PHP中使用CURL实现GET和POST请求
- PHP单引号和双引号的区别
- 辛星浅析php变量中的优先级问题
- thinkphp实现导航高亮的简单方法
- php7 安装
- php 获得当月属于那季度和当前季度的第一个月
- php安装扩展
- php 变量
- PHP腾讯地图经纬度转百度地图经纬度/PHP cURL 带cookies模拟HTTP/PHP发送邮件
- PHP函数count、strlen效率分析
- Ubuntu下的PHP开发环境架设
- php数字操作,高精度函数,保留计算结果小数位