legend3---Windows 7/8/10 系统下Laravel框架的开发环境安装及部署详解(Vagrant + Homestead) (4)

用notepad++打开即可:

# Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a \'#\' symbol. # # For example: # # 102.54.94.97 rhino.acme.com # source server # 38.25.63.10 x.acme.com # x client host # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost # 添加上这一行,将phantastic.test替换成自己的项目名称 192.168.10.10 phantastic.test

这里我们需要将项目地址解析到对应的虚拟机IP(192.168.10.10)。
然后我们以管理员权限保存hosts文件。

接下来我们来看最后一段配置:

databases: - homestead

这段配置指定了我们虚拟机中MySQL的数据库名,我们每新添加一个数据库名字,那么Homestead将会自动创建一个该名字的数据库来供我们操作。

在这里,我添加了两个新的数据库,并删除了原始配置中的homestead数据库:

databases: - phantastic - eagle

注意:配置文件中不要使用tab来留空,否则可能会报错(可以用空格对齐)。

虚拟机环境下默认的MySQL服务器管理员用户名为homestead,密码是secret。推荐使用phpmyadmin或adminer.php来进行数据库管理,当然如果你hardcore,直接mysql -u homestead -p也可以。

另外每个项目如果需要更改项目默认使用的数据库等配置,可以在创建Laravel项目后配置根目录下的.env文件
详情请查看 Laravel 5+ .env 环境配置文件详解

至此,Homestead就配置完成了。我们将Homestead.yaml保存,然后尝试启动虚拟机!(激动吗;)?)

以管理员的身份打开Git Bash,输入

$ cd ~/homestead $ vagrant up

我们会看到,Vagrant已经顺利运行了(Windows环境下vagrant up不需要加sudo)!
接下来,要进入Homestead,我们输入

$ vagrant ssh

进入虚拟机环境后:

# cd 进入我们共享的文件夹 (请根据你配置中的映射目录来输入相应文件夹) $ cd /var/www # 创建一个新的laravel项目 $ laravel new eagles_new_project

现在我们就可以开始Laravel的开发了!

注意:如果你vagrant up后,卡在ssh命令,很久后显示超时,那么请重启系统进入BIOS,将Intel的VT-x功能开启并保存再继续即可。

From:https://blog.sbot.io/articles/1

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzdfsd.html