在 Windows10 系统中安装 Homestead 本地开发环境
在 windows10 系统中安装 homestead 本地开发环境
在 windows10 环境下安装 homestead 开发环境,网上有很多相关教程其中大多都是 mac 环境,很多大神都是用户的 mac 。 但是还是有很多像我这样的小弟还是用的 windows 系统,而在 win10 系统上面因为权限问题安装 homestead 还是有各种问题发生。
需求:
安装完 VirtualBox 5.2 和 Vagrant 你可以在终端中执行下面的命令将 laravel/homestead box 添加到 Vagrant 中安装(如果你出现下载很慢,或者无法下载的问题,可以开启一个vpn ,这里推荐一个免费的 setupVpn)
vagrant box add laravel/homestead
如果你的网络实在不好,我就碰到过公司网络超级慢的公司。可以使用本地安装的方法。
https://www.jianshu.com/p/ae9...
注意:我们下载box的时候最好下载最新的版本,如果下载的box和后面的homestead 版本不相配可能会 出现各种奇怪的问题
安装 Homestead
你可以通过克隆仓库代码来实现 Homestead 安装。将仓库克隆到用户目录下的 Homestead 目录,这样 Homestead 盒子就可以作为所有其他 Laravel 项目的主机:
git clone https://github.com/laravel/homestead.git homestead
克隆完成后,我们切换到最新的分支版本 v7.14.2 ,我们用的最新homestead.box 6.3.0:
// Clone the desired release...
git checkout v7.14.2
接下来,在 Homestead 目录下运行 bash init.sh 命令来创建 Homestead.yaml 配置文件,生成的 Homestead.yaml 配置文件文件位于当前 Homestead 目录:
bash init.sh
配置 Homestead.yaml
name: homestead
ip: 192.168.10.10
memory: 2048
cpus: 2
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
-
map: 'D:\webroot\'
to: /home/vagrant
type: nfs
sites:
-
map: homestead.test
to: /home/vagrant/homestead/public
databases:
- homestead-test
nfs 模式就要是提升虚拟机和本机之间的文件读取速度,可以不开启 nfs, 如果要开启可以参考这篇教程 解决 Windows 系统使用 Homestead 运行 Laravel 本地项目响应缓慢问题
不要忘记把 Nginx 站点配置中的域名添加到本地机器上的 hosts 文件中,该文件会将对本地域名的请求重定向到 Homestead 虚拟机,在 Mac 或 Linux上,该文件位于 /etc/hosts,在 Windows 上,位于 C:WindowsSystem32driversetchosts,添加方式如下:
192.168.10.10 homestead.test
启动 Vagrant 盒子
配置好 Homestead.yaml 文件后,在 Homestead 目录下运行 vagrant up 命令,Vagrant 将会启动虚拟机并自动配置共享文件夹以及 Nginx 站点,初次启动需要花费一点时间进行初始化:
Administrator@SC-201808141722 MINGW64 /d/homestead ((v7.14.2))
$ vagrant up --provision
==> vagrant: A new version of Vagrant is available: 2.1.4!
==> vagrant: To upgrade visit: https://www.vagrantup.com/downloads.html
Bringing machine 'homestead' up with 'virtualbox' provider...
==> homestead: Checking if box 'laravel/homestead' is up to date...
==> homestead: Clearing any previously set forwarded ports...
==> homestead: Clearing any previously set network interfaces...
==> homestead: Preparing network interfaces based on configuration...
homestead: Adapter 1: nat
homestead: Adapter 2: hostonly
==> homestead: Forwarding ports...
homestead: 80 (guest) => 8000 (host) (adapter 1)
homestead: 443 (guest) => 44300 (host) (adapter 1)
homestead: 3306 (guest) => 33060 (host) (adapter 1)
homestead: 4040 (guest) => 4040 (host) (adapter 1)
homestead: 5432 (guest) => 54320 (host) (adapter 1)
homestead: 8025 (guest) => 8025 (host) (adapter 1)
homestead: 27017 (guest) => 27017 (host) (adapter 1)
homestead: 22 (guest) => 2222 (host) (adapter 1)
==> homestead: Running 'pre-boot' VM customizations...
==> homestead: Booting VM...
==> homestead: Waiting for machine to boot. This may take a few minutes...
homestead: SSH address: 127.0.0.1:2222
homestead: SSH username: vagrant
homestead: SSH auth method: private key
homestead: Warning: Connection reset. Retrying...
homestead: Warning: Connection aborted. Retrying...
homestead: Warning: Connection reset. Retrying...
homestead: Warning: Connection aborted. Retrying...
homestead: Warning: Connection reset. Retrying...
homestead: Warning: Connection aborted. Retrying...
==> homestead: Machine booted and ready!
==> homestead: Checking for guest additions in VM...
==> homestead: Setting hostname...
==> homestead: Configuring and enabling network interfaces...
==> homestead: Running provisioner: shell...
homestead: Running: script: Creating Certificate: homestead.test
==> homestead: Running provisioner: shell...
homestead: Running: script: Creating Site: homestead.test
==> homestead: Running provisioner: shell...
homestead: Running: inline script
==> homestead: Running provisioner: shell...
homestead: Running: script: Checking for old Schedule
==> homestead: Running provisioner: shell...
homestead: Running: script: Clear Variables
homestead: sed: can't read /home/vagrant/.profile: No such file or directory
==> homestead: Running provisioner: shell...
homestead: Running: script: Restarting Cron
==> homestead: Running provisioner: shell...
homestead: Running: script: Restarting Nginx
==> homestead: Running provisioner: shell...
homestead: Running: script: Creating MySQL Database: homestead-test
==> homestead: Running provisioner: shell...
homestead: Running: script: Creating Postgres Database: homestead-test
==> homestead: Running provisioner: shell...
homestead: Running: script: Update Composer
homestead: You are already using composer version 1.7.2 (stable channel).
==> homestead: Running provisioner: shell...
homestead: Running: C:/Users/ADMINI~1/AppData/Local/Temp/vagrant-shell20180903-12352-ohdsb3.sh
里面会显示出创建的站点和数据库等信息 ,现在就可以通过 homestead.test 访问你的项目了。