搭建Ubuntu PHP开发环境(使用Vagrant+Homstead+VirtualBox)

安装 virtualbox 和 vagrant

这里下载并安装 VirtualBox , Vagrant .

 

下载并配置 Homestead

Homestead 包括以下两个东西

  1. 一个 vagrant box 虚拟机, 里面软件什么都下载好了;
  2. Github 代码库, 里面装载着 vagrant 的配置脚本, 用来自动化配置网络, 端口映射, 等一些开发时候用到的配置;

打开终端(git-bash)克隆 homestead 项目到本地 

git clone https://github.com/laravel/homestead.git Homestead

下载完成之后,进入Homestead目录,双击init.bat安装(或者直接在终端执行  bash  init.sh 安装)homestead。

安装成功会生成目录.homestead,目录下面的Homestead.yaml 为 homestead 配置文件

C:\Users\Administrator\.homestead

---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: G://homestead
      to: /home/vagrant/Code

sites:
    - map: homestead.app
      to: /home/vagrant/Code/Laravel/public

databases:
    - homestead

folders 为映射目录 map 源目录 就是本地的开发目录 to 是虚拟机开发目录

sites 配置多个项目

    - map: homestead.app
      to: /home/vagrant/Code/Laravel/public

    - map: order.app
      to: /home/vagrant/Code/order/public

authorize  SSH的公钥

生成SSH密匙

打开git-bash执行下面命令

ssh-keygen -t rsa -C "you@homestead"
$ ssh-keygen -t rsa -C "you@homestead"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Created directory '/c/Users/Administrator/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:nN9YYWBP0Zgce4uLmvvrlzThxkSlKKqoF+7x4knSILs you@homestead
The key's randomart image is:
+---[RSA 2048]----+
|          o.+B.  |
|         . ==o.  |
|        . ..* .  |
|       o o .o+ . |
|o     . S  +o..  |
|.+.. .   . =*.   |
|o.=..     +ooo   |
| =++     o  o    |
|E++..   +++o     |
+----[SHA256]-----+

生成成功。

 

下载和安装  laravel/homestead 

https://atlas.hashicorp.com/laravel/boxes/homestead 包的列表。

直接用

vagrant box add laravel/homestead

或者

vagrant box add laravel/homestead https://atlas.hashicorp.com/laravel/boxes/homestead

由于不科学上网,上面操作会超慢。建议直接用迅雷下载(下面操作)。

直接复制下面链接到迅雷新加项目下载(0.5.0就是homestead的版本)

https://vagrantcloud.com/laravel/boxes/homestead/versions/0.5.0/providers/virtualbox.box

使用 vagrant box add laravel/homestead  G://homestead.box  会出现版本号为 0 的情况,所以以配置方式添加包。

http://stackoverflow.com/questions/34946837/box-laravel-homestead-could-not-be-found

Homestead目录下新加文件metadata.json(配置版本号)。G://homestead.box 为下载的包路径。

{
    "name": "laravel/homestead",
    "versions": [{
	      "version": "0.5.0",
		  "providers": [{
			    "name": "virtualbox",
				"url": "G://homestead.box"
		 }]
	}]
}

在终端(git-bash)进入Homestead目录,执行以下命令。

vagrant box add metadata.json
$ vagrant box add metadata.json
==> box: Loading metadata for box 'metadata.json'
    box: URL: file://C:/Users/Administrator/Homestead/metadata.json
==> box: Adding box 'laravel/homestead' (v0.5.0) for provider: virtualbox
    box: Downloading: G://homestead.box
    box:
==> box: Successfully added box 'laravel/homestead' (v0.5.0) for 'virtualbox'!

添加完成。

在Homestead目录执行 

vagrant up
$ vagrant up
Bringing machine 'homestead-7' up with 'virtualbox' provider...
==> homestead-7: Importing base box 'laravel/homestead'...
==> homestead-7: Matching MAC address for NAT networking...
==> homestead-7: Checking if box 'laravel/homestead' is up to date...
==> homestead-7: Setting the name of the VM: homestead-7
==> homestead-7: Clearing any previously set network interfaces...
==> homestead-7: Preparing network interfaces based on configuration...
    homestead-7: Adapter 1: nat
    homestead-7: Adapter 2: hostonly
......

下载我们最喜欢的Laravel,然后放到G://homestead/。因为是映射关系,所以/home/vagrant/Code/Laravel/public 对应是 G://homestead/Laravel/public 。

    - map: homestead.app
      to: /home/vagrant/Code/Laravel/public

最后在本机hosts加上 

192.168.10.10  homestead.app

然后访问http://homestead.app/。

Mysql 默认的用户 为homestead 密码 secret,可以使用mysql管理工具直接连接192.168.10.10。

进入虚拟机服务器,Homestead目录执行 vagrant ssh ,其他命令可以使用 vagrant -h 查看。

记住在虚拟机运行中,修改Homestead.yaml之后,在Homestead目录执行   vagrant provision  重新加载配置。

homestead包已安装的软件

  • Ubuntu 14.04
  • Git
  • PHP 5.6 / 7.0
  • Xdebug
  • HHVM
  • Nginx
  • MySQL
  • Sqlite3
  • Postgres
  • Composer
  • Node (With PM2, Bower, Grunt, and Gulp)
  • Redis
  • Memcached (PHP 5.x Only)
  • Beanstalkd
  • Laravel Envoy
  • Blackfire Profiler

转载于:https://my.oschina.net/xinson/blog/786635

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值