Homestead 添加新站点

发布 : 2019-05-26 分类 : 服务器 浏览 :

配置Homestead

配置文件路径是: ~/Homestead/Homestead.yaml

配置文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Code
to: /home/vagrant/Code
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
databases:
- homestead

配置示例: 新增一个网站”blog.test”:

1. 新增网站目录,比如blog:

在Code目录中新增一个blog目录,作为新增网站的根目录: 创建一个index.html文件,随便写写内容,路径如下: ~/Code/blog

2. 增加sites:

1
2
3
4
5
6
7
8
9
10
11
$ vim ~/Homestead/Homestead.yaml

//在sites中新增一条map记录,修改后配置如下:
//配置中的xunij “/home/vagrant/Code/kaixin123net” 对应我们本地的 "~/Code/kaixin123net"
sites:
### 默认
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
### 新增加一个网站,域名为kaixin123.app
- map: kaixin123.app
to: /home/vagrant/Code/kaixin123net

3. 新增一条hosts记录:

1
2
3
4
5
$ sudo vim /etc/hosts

//新增一条host记录,IP是Homestead.yaml中“ip”,修改后如下:
192.168.10.10 homestead.app
192.168.10.10 blog.test

4. 重启vagrant虚拟机:

进入~/Homestead/目录

1
cd ~/Homestead/

重新加载配置并登录虚拟机

1
vagrant provision && vagrant ssh

有Code文件夹,这个/home/vagrant/Code与本机的~/Code目录会保持同步

1
2
vagrant@homestead:~$ ls
Code

退出虚拟机

1
2
3
vagrant@homestead:~$ exit
logout
Connection to 127.0.0.1 closed.

4. 连接Homestead数据库:

地址: 192.168.10.10
端口: 3306

用户名: homestead

密码: secret

登录虚拟机数据库:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
vagrant@homestead:~$ mysql -h192.168.10.10 -uhomestead -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 51
Server version: 5.7.13-0ubuntu0.16.04.2 (Ubuntu)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| homestead |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql>

结语

以上步骤都顺利完成后,那么恭喜你新站点已经添加成功了!赶紧去试试吧!

知识 & 情怀 | 二者兼得

微信扫一扫, 向我投食

微信扫一扫, 向我投食

支付宝扫一扫, 向我投食

支付宝扫一扫, 向我投食

留下足迹