Windows上使用Vagrant打造Laravel Homestead可协同跨平台开发环

前言

大家对VMware或者VirtualBox一定不会陌生,虚拟化的好处自然深入人心,而现在我们可以通过Vagrant搭建一套类似Laravel Homestead完整开发环境,这样极大的减少了架设开发环境的时间,同时还支持在Windows/Mac/Linux不同平台上分享定制包,统一团队之间的开发环境提高工作效率,而Docker的出现也让未来更值得期待。

用Vagrant为自己打造一个奇妙的跨平台开发环境

更新历史

2015年07月18日 – 初稿

阅读原文 –

扩展阅读

Vagrant – https://www.vagrantup.com/ Laravel Homestead – 在windows下进行linux开发:利用Vagrant+virtualbox – 在 Mac/win7 下上使用 Vagrant 打造本地开发环境 –

环境准备

如果大家有需要离线安装欢迎直接留言回复哈

安装git

1.下载GitHub for Windows

https://windows.github.com/

安装php

建议大家尽量安装当前最新版本的 PHP

1.下载PHP

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.下载Laravel

2.解压目录

我的路径D:\laravel-v5.1.4

3.启动Laravel

d:cd laravelD:php artisan serveLaravel development server started on http://localhost:8000/

在浏览器中访问:8000/

artisan 的 serve 命令还支持两个参数:

host 设置主机地址 port 设置 web server 监听的端口号 例如:php artisan serve –port=8888

安装Composer

1.下载Composer-Setup.exe

2.配置Composer

Loading composer repositories with package informationInstalling 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”

如果安装过程提示报错为缺少CA证书,下载cacert.pem到自定义路径

然后修改php.ini文件(1983行左右)

openssl.cafile=D:\php\verify\cacert.pem

3.测试Composer

composer -VComposer version :22:58安装Vagrant

1.下载Vagrant

https://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镜像下载链接,要下载其他镜像请访问官网

安装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

#切换VirtualBox目录e:cd .\VirtualBox#输入命令初始化E:\VirtualBox> vagrant init centos6.6A `Vagrantfile` has been placed in this directory. You are nowready to `vagrant up` your first virtual environment! Please readthe 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.boxbox: Progress: 100% (Rate: 670M/s, Estimated time remaining: –:–:–)==> box: Successfully added box ‘centos6.6’ (v0) for ‘virtualbox’!#检查是否导入成功E:\VirtualBox> vagrant box listcentos6.6 (virtualbox, 0)Vagrant配置

详细配置文档可以参考官方手册 – https://docs.vagrantup.com/v2/

启动Vagrant

通过Shell进入目录E:\VirtualBox后执行命令

vagrant up

顺利启动的完整过程如下所示

E:\VirtualBox>vagrant upBringing machine ‘default’ up with ‘virtualbox’ provider…==> default: Importing base box ‘centos6.6’…==> default: Matching MAC address for NAT networking…==> default: Setting the name of the VM: VirtualBox_default_1437213832296_68434==> default: Clearing any previously set forwarded ports…==> default: Clearing any previously set network interfaces…==> default: Preparing network interfaces based on configuration…default: Adapter 1: nat==> default: Forwarding ports…default: 22 => 2222 (adapter 1)==> default: Booting VM…==> default: Waiting for machine to boot. This may take a few minutes…default: SSH address: 127.0.0.1:2222default: SSH username: vagrantdefault: SSH auth method: private keydefault: Warning: Connection timeout. Retrying…default:default: Vagrant insecure key detected. Vagrant will automatically replacedefault: this with a newly generated keypair for better security.default:default: Inserting generated public key within guest…default: Removing insecure key from the guest if it’s present…default: Key inserted! Disconnecting and reconnecting using new SSH key…==> default: Machine booted and ready!==> default: Checking for guest additions in VM…default: The guest additions on this VM do not match the installed version ofdefault: VirtualBox! In most cases this is fine, but in rare cases it candefault: prevent things such as shared folders from working properly. If you seedefault: shared folder errors, please make sure the guest additions within thedefault: virtual machine match the version of VirtualBox you have installed ondefault: your host and reload your VM.default:default: Guest Additions Version: 4.3.28default: VirtualBox Version: 5.0==> default: Mounting shared folders…default: /vagrant => E:/VirtualBox有我们特有的记忆,亲情之忆友谊之花爱情之树以及遗憾之泪!

Windows上使用Vagrant打造Laravel Homestead可协同跨平台开发环

相关文章:

你感兴趣的文章:

标签云: