Laravel教程 一:安装及环境配置

JellyBool

JellyBool

最近在SF上面看到越来越多的Laravel相关的问题,而作为一个Laravel的脑残粉,本来打算有机会录视频教程放出来的,不过这个计划貌似由于某些原因必须得推迟一段时间,所以现在先把文章的系列教程写出来吧。

首先需要说明的是,这个教程对于完全没有上手Laravel的人来说,我尽量将一些概念和重点说清楚,不过你也不需要担心这需要花很多时间来跟着这个教程学习Laravel,我相信,如果你认认真真跟着教程将代码敲过一遍,相信你对Laravel会有一个清晰的认识。

开始之前:这个教程打算是每天一篇,首先是会涵盖很多Laravel的基础知识。然后我还打算出教程说说Laravel的Eloquent和它的一些棒的特性比如Schedule Command等,至于是博客的形式还是录视频的形式,后面看情况吧,所以现在是开始我们的Laravel教程了。

这一节的内容:

  1. 我首先会说明怎么安装Laravel

  2. 说说Homestead这个开发环境

安装Laravel

本系列教材基于Laravel 5.1 稳定版

恩,像几乎所有框架的开始一样,我们需要知道怎么安装Laravel。

这里首推的是使用Composer安装Laravel,如果你还没有接触过Composer,你可以到官网这里来看看:

安装:https://getcomposer.org/download/

文档:https://getcomposer.org/doc/

这里给出的建议是,如果你希望在PHP这条道路走下去,那么你必须学会使用Composer,不要将PHP的印象停留在10年之前了,我们(PHP开发者)也是有很棒的工具的!

替代文字

如果你的机子上安装过Composer,请忽略上面的话。

上面的废话说完了,直接进入正题:

博主的代码放在~/Code目录之下,也就是打开命令行工具,直接就cd Code/就可以进入到我的项目代码目录

在Code/目录下执行Composer安装命令:

composer create-project laravel/laravel blog

上面的命令通常是需要等一段时间才可以完成Laravel的安装(请使用VPN),趁这个机会来说说Composer的一小点知识。

上面的命令就是使用Composer的create-project命令创建一个新的项目,这个项目的名称就是blog,也就是我们会在Code/目录之下得到一个blog/文件夹,至于laravel/laravel也就是Laravel提供的包名称,如果你想知道Composer究竟有哪些包,你可以直接到这里来看看:

https://packagist.org/explore/

比如一些很常用的包:phpspec,phpunit,behat,yii....你都可以在这里找到:

替代文字

你可以在上面找到几乎所有跟PHP开发相关的东西,比如你可以随便搜一个password,你可以得到很多对密码处理的包:

替代文字

等待安装好之后,在Code/目录下就可以看到我们的blog/项目了:

替代文字

安装完Laravel之后,我们怎么使用呢?也就是我们怎么在浏览器中输入相对应得url来访问到我们的Laravel呢?这里你有三个选择:

  1. 使用PHP自带的服务器

进入到项目的对应目录cd blog/,开启PHP服务器:

php -S localhost:8999 -t public

然后访问localhost:8999就可以看到Laravel的首页了:

替代文字

  1. 使用artisan

依然是在blog/目录之下,命令行执行:

php artisan serve

然后访问localhost:8000,你也可以看到相对应的Laravel默认页面:

替代文字

这里其实是也使用PHP自带的服务器,不过Laravel给我们封装了一个命令行工具:artisan。如果你不想使用第三种方法,推荐你在开发的时候直接使用这一种来进行。

blog/目录下敲命令artisan,你就可以看到Laravel的artisan其实可以做很多事情,我们后面会讲到。

替代文字

  1. 使用Homestead

Homestead是Laravel官方出的一个虚拟开发环境,在这个环境里面,你不用担心服务器的配置和文件夹得权限配置等,因为在Homestead当中,这些都是已经为你准备好的。而且有很大得好处就是,如果你是进行多人的团队开发工作,你们的团队的开发环境可以做到一模一样,就不用担心你某次升级到最新版本的操作系统而破坏你的开发环境了。所以,我是推荐大家使用Homestead,虽然第一次接触这些可能你会觉得有点麻烦,但是一旦你习惯和配置好了这个虚拟的开发环境,在以后的开发当中,你就可以避免很多不必要的问题。

所以,以后的系列教程会基于Homestead,你也可以直接使用第二种方式。

首先是安装Homestaed,因为Homestead依赖于Vagrant,我这里的虚拟机使用的是VirtualBox所以,首先我们需要安装这两个东西:

VirtualBox : https://www.virtualbox.org/wiki/Downloads

Vagrant : https://www.vagrantup.com/downloads.html

上面这两个下载链接种,选择适合你自己操作系统的版本进行下载,安装。

安装完这两个之后,我们就可以安装我们的Homestead了:

vagrant box add laravel/homestead

一会之后,你就会看到类似这个页面:

~  vagrant box add laravel/homestead
==> box: Loading metadata for box 'laravel/homestead'
    box: URL: https://atlas.hashicorp.com/laravel/homestead
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.

1) virtualbox
2) vmware_desktop

Enter your choice: 1

选择1,然后等待安装,这个过程可能需要等待一下(少年,开VPN吧!)

安装完了之后,我们就可以进行Homestead的简单配置了,命令行执行:

homestead edit

然后就可以看到我们的Homestead.yaml配置文件的内容了:

替代文字

我们需要注意红色框框里面的内容:

folders:
    - map: ~/Code
      to: /home/vagrant/Code
sites:
    - map: blog.dev
      to: /home/vagrant/Code/blog/public

folders是配置vagrant的映射文件夹,这里也就是我们的~/Code映射到Homestead虚拟机中的/home/vagrant/Code文件夹,简单的理解是如果我们在~/Code这个文件夹内做的任何修改,vagrant都会马上同步到/home/vagrant/Code中,(后面我们可以ssh登录到Honestead中去看看这个文件夹);然后sites就是我们的站点配置,这里我们将blog.dev这个域名映射到/home/vagrant/Code/blog/public目录,这个是因为我们在上面的folders映射了/home/vagrant/Code这个文件夹,我们就可以想象到这个文件夹下面就有一个blog/目录,而这个就是我们的项目目录,所以这里指定的其实就相当于我们使用PHP自带服务器并指定根目录一个效果:

php -S localhost:8999 -t public

修改本机的hosts文件:

sudo vim /etc/hosts

在这个文件后面加上下面这一行:

192.168.10.10  blog.dev

替代文字

到这里,Homestead的配置已经完成了,这个时候,你只需要命令行执行一下:

homestead up

等待虚拟机启动起来,然后访问http://blog.dev/,你就可以看到熟悉的页面了:

替代文字

登录Homestead

在命令行直接执行:

homestead ssh

然后你就可以登录到Homestead这个虚拟机当中了:

替代文字

图中的Code/文件夹就是我们上面在Homestead.yaml配置的映射文件夹,里面就有我们的blog/项目。后续的开发都是基于在这个虚拟机之上的,当然,你也可以直接使用php artisan serve

下一节

这一篇主要是Laravel的安装和环境配置,下一节我将介绍Laravel的Router,Views和Controllers,相信这个介绍完了之后,你对Laravel的认识会比较清晰了。

Happy Hacking

本文由 JellyBool 创作, 转载和引用遵循 署名-非商业性使用 2.5 中国大陆 进行许可。

共有 94 条评论

JellyBool

测试一下回复功能不能正常使用

JellyBool

这里反而可以使用,好奇怪啊

TimeIsGoOn

挺好的,界面也很好看

JellyBool

@TimeIsGoOn 谢谢,有些小东西需要优化一下,后面的文章我会先同步到这里

TimeIsGoOn

学习记录
使用 composer
我的系统是ubutnu 麒麟版 15.04,
使用
composer create-project laravel/laravel blog
报错
Failed to decode response: zlib_decode(): data error
Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info

然后我用了 (新的composer源)[http://pkg.phpcomposer.com/]
命令
composer config -g repositories.packagist composer http://packagist.phpcomposer.com

最后安装的很快,并且没有错误

openwrtmail

@TimeIsGoOn ##加油##

TimeIsGoOn

以前没有接触过这个虚拟机的概念,搜了一下,这个的意思是安装的是一个盒子,这个盒子里的环境是都安装好的,即使我的电脑没有安装php,nginx,mysql,也能在这个盒子里使用mysql,php,nginx等等,我想问怎么看这个盒子里有哪些环境呢?比如我想知道有没有安装redis,git,有没有composer,甚至php有没有我想用的扩展的?比如swoole,yaf什么的,
如果没有,我又怎么进行安装呢?
如果 我按装好了,又如何将这个环境(box)转移到其他地方呢?
这个虚拟机概念很好奇
还有,能推荐个VPN吗,
这个盒子
https://atlas.hashicorp.com/laravel/boxes/homestead/versions/0.2.7/providers/virtualbox.box
929M 真是蛮大的

TimeIsGoOn

找到了这个,不过是全英文的
这个是首页
https://docs.vagrantup.com/v2/getting-started/boxes.html
这里是资源包
https://atlas.hashicorp.com/boxes/search?utf8=✓&sort=&provider=&q=laravel
又学到新东西了

TimeIsGoOn

问题记录
命令
vagrant box add laravel/homestead
下了很久之后报错

An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.

HTTP server doesn't seem to support byte ranges. Cannot resume.

之后再次执行命令时一直报错,
这里需要把
~/.vagrant.d/tmp/ 的 文件删除
删除后再次执行就可以重新下载

TimeIsGoOn

教程从 vagrant box add laravel/homestead 之后出现了问题
第一是这个命令执行完成
在~/.vagrant.d/boxes 文件夹下多了一个文件
laravel-VAGRANTSLASH-homestead
文件的结构如下

du -ah
12K	./0.2.7/virtualbox/box.ovf
4.0K	./0.2.7/virtualbox/metadata.json
4.0K	./0.2.7/virtualbox/Vagrantfile
946M	./0.2.7/virtualbox/box-disk1.vmdk
946M	./0.2.7/virtualbox
946M	./0.2.7
4.0K	./metadata_url
946M	.

ls
0.2.7  metadata_url

此时 执行 homestead edit 会报错说没有这个homestead命令
搜了一下
资料1
资料2
里面提到要git

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

但是clone 完成后文件夹下没有Homestead.yaml 文件
而在这个Homestead文件夹下使用 composer update 之后执行

./homestead  edit
xdg-open: file '/home/sun/.homestead/Homestead.yaml' does not exist

然后卡在这里了

TimeIsGoOn

对了 ,我按装

VirtualBox : https://www.virtualbox.org/wiki/Downloads

Vagrant : https://www.vagrantup.com/downloads.html

这两个是直接下载的对应的 deb包,执行 dpkg -i 进行的安装

TimeIsGoOn

感谢,我找到了官网的说明,看来网上有的资料确实太老了
官网说明 homestead
不过我又出现了一个问题

sun@sun:~/Homestead$ ./homestead up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'laravel/homestead'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'laravel/homestead' is up to date...
==> default: Setting the name of the VM: homestead
==> default: Clearing any previously set network interfaces...
The specified host network collides with a non-hostonly network!
This will cause your specified IP to be inaccessible. Please change
the IP or name of your host only network so that it no longer matches that of
a bridged or non-hostonly network.

TimeIsGoOn

评论如果能有个修改的功能就太好了,自己能改自己的评论,这样会方便很多


ip我使用的是ifconfig的ip,结果启动后报了上面那个错,我改成127.0.0.1 后好了 我的配置文件如下 ``` sun@sun:~/.homestead$ cat Homestead.yaml --- ip: "127.0.0.1" 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/blog/public

databases:
- homestead

variables:
- key: APP_ENV
value: local

blackfire:

- id: foo

token: bar

client-id: foo

client-token: bar

ports:

- send: 93000

to: 9300

- send: 7777

to: 777

protocol: udp

进入虚拟机后的路径如下

sun@sun:~/Homestead$ ./homestead ssh
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-24-generic x86_64)

  • Documentation: https://help.ubuntu.com/
    Last login: Mon Sep 7 23:16:54 2015 from 10.0.2.2
    vagrant@homestead:~$ ls
    Code
    vagrant@homestead:~$ cd Code/
    vagrant@homestead:~/Code$ ls
    blog vagrant_1.7.4_x86_64.deb
    socially virtualbox-5.0_5.0.2-102096-Ubuntu-trusty_amd64.deb
    vagrant@homestead:~/Code$ cd blog/
    vagrant@homestead:~/Code/blog$ pwd
    /home/vagrant/Code/blog
    vagrant@homestead:~/Code/blog$ ls
    app composer.lock package.json readme.md tests
    artisan config phpspec.yml resources vendor
    bootstrap database phpunit.xml server.php
    composer.json gulpfile.js public storage
这个文件的映射是对了,
我执行

sun@sun:~/Homestead$ ./homestead up
Bringing machine ‘default’ up with ‘virtualbox’ provider…
==> default: You assigned a static IP ending in “.1” to this machine.
==> default: This is very often used by the router and can cause the
==> default: network to not work properly. If the network doesn’t work
==> default: properly, try changing this IP.
==> default: You assigned a static IP ending in “.1” to this machine.
==> default: This is very often used by the router and can cause the
==> default: network to not work properly. If the network doesn’t work
==> default: properly, try changing this IP.
==> default: Checking if box ‘laravel/homestead’ is up to date…
==> default: VirtualBox VM is already running.

服务也是运行了
再看 hosts

sun@sun:~/Homestead$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 sun
127.0.0.1 homestead.app

The following lines are desirable for IPv6 capable hosts

::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

homestead.app的加上了
同时避免干扰我停了apache

root@sun:~# ps aux |grep apache
root 10828 0.0 0.0 11188 2352 pts/4 S+ 07:25 0:00 grep --color=auto apache

浏览器打开
http://homestead.app/
显示的是 无法访问
打开
http://homestead.com:8000/
显示的也是 无法访问
我真是不知道错在哪里
JellyBool

@TimeIsGoOn 首先是很抱歉现在才回复你的评论。

关于你的问题,现在一一解答。

1.其实homestead你完全可以看做一个普通的虚拟机,打开virtualbox,你一般就会看到default和homestead这两个虚拟机了,在你的系统上就相当于用命令行安装了一个ubuntu在virtualbox上,如果你想查看这个homestead的虚拟机安装了哪些开发用的或者还有安装其他的开发组件,如redis等,可以直接ssh登录homestead,然后使用apt-get,就像使用本机的ubuntu一样。

2.关于VPN,在国内,我一直都是极力推荐做开发的人都使用VPN的,这样可以避免很多不必要的问题,10多块钱一个月换来的是网络自由,我觉得很值。我一直使用的是GreenVPN,百度搜索出来的冒牌货很多,链接在这里:GreenVPN

关于使用git clone的方式,在有了Homestead/这个文件夹之后,还需要执行一步:

bash init.sh

来初始化Homestead,也就是这个命令才会生成Homestead.yaml文件。

关于hosts'文件配置,127.0.0.1 homestead.app`将这个改成下面这个试试:

192.168.10.10  homestead.app

关于评论的编辑功能,今天可以上线吧

以上,Happy Hacking

TimeIsGoOn

非常感谢,晚上回去再试试

JellyBool

@TimeIsGoOn 恩恩,有什么问题也是可以直接在这里讨论。你说需不需要回复一个评论就发送一封邮件给你提醒一下?

JellyBool

@TimeIsGoOn 评论编辑功能已经简单实现,你试试

TimeIsGoOn

这次开机访问 http://homestead.app:8000/ 正常了又,
真是不明白怎么回事
我希望访问 http://homestead.app就能用,应该怎么改?(我看文档里没有说需要特别加上8000端口号的,可是我去掉就不行了)

JellyBool

@TimeIsGoOn 理论上是不用的8000端口的,不知道你配置过其他东西没有

TimeIsGoOn

感谢你的回答,
我发现官网上说的是

Ports

By default, the following ports are forwarded to your Homestead environment:

SSH: 2222 → Forwards To 22
HTTP: 8000 → Forwards To 80
HTTPS: 44300 → Forwards To 443
MySQL: 33060 → Forwards To 3306
Postgres: 54320 → Forwards To 5432

虚拟机接受的是发送8000 端口的
为什么又不用8000端口呢
期待这个能出一个完整的视频

JellyBool

@TimeIsGoOn 录视频这件事,由于本人的首次尝试,还是遇到挺多阻碍的,不过会尽量出

simond

我是linuxmint,homestead折腾了好久还是用不上,接下来的学习 直接用artisan没问题吧

JellyBool

@simond 没有问题

mpanda

08年接触php,11年毕业后两年脱离php,13年底重拾php开发,php的变化节奏非常之快,绝大多数的培训机构以及老程序员都停留在了php5.3,框架更是停留在了tp,yii1等等架构,甚至是discuz、织梦cms等,对于最新的composer和laravel等呈现出严重的抵触感。

再次接触到larvael和composer后有种相见恨晚的赶脚。遂遍查了国内的php社区现状,不少phper建立了laravel社区,比如王赛建立的golaravel.com,phphub(laravel-china)包括楼主建立的这个社区,楼主的视频教程是我觉得做的最好的,不过感觉很难成系列并延续下去。

我是来支持楼主的!

JellyBool

@mpanda 谢谢支持,尽量坚持吧,打算开始系列视频了,今天会录第一个。

xuan9230

very good tutorial! sorry don’t have Chinese input, just have a question:
I’m using composer/laravel installer instead of homestead, and have been struggling with how to set url… tried to replace line 29 in app.php in config, from ‘url’ => ‘http://localhost’ to ‘url’ => ‘http://a.io’, but id doesn’t work when typing a.io in browser.
How to fix that? Many thanks!

JellyBool

i think the url setting here is for the artisan cli console tool,for example, you may run a artisan queue:listen command ,and that is the url the command listen ,if you want to use

http://a.io

i recommend Homestead

JellyBool

@xuan9230 any questions,come to me

walterlize

您好,我参照了您的、官方的教程,安装了homestead,配置了homestead.yaml文件。其中

folders:
    - map: ~/Code
      to: /home/vagrant/Code
      type: "nfs"

但是,在homestead up 之后输入url后一直抱502的错误。我homestead ssh登陆后发现/home/vagrant/Code下没有我放在~/Code下面的项目,就是说没有自动的sync,尝试了一些方法,但是还是没有解决,不知道您碰到过这种问题没有? 谢谢!

JellyBool

你的操作系统和项目文件目录能不能贴出来看看,BTW,可以尝试使用markdown @walterlize

walterlize

1、现在的系统是昨天刚更新的OS X 10.11,但是前几天第一次尝试的时候也是有这个问题。
2、初次使用为了保证没问题,文件目录跟您的教程一致。

‘Last login: Sat Oct  3 13:12:39 on ttys001
lzdeMacBook-Pro:blog walter$ cd ~/Code
lzdeMacBook-Pro:Code walter$ ls
blog		lee.doc		pavilion
lzdeMacBook-Pro:Code walter$ homestead ssh
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-24-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
Last login: Fri Oct  2 16:51:43 2015 from 10.0.2.2
vagrant@homestead:~$ cd /home/vagrant/Code
vagrant@homestead:~/Code$ ls -a
.  ..
vagrant@homestead:~/Code$ ’

设置同步的Homestead.yaml文件

‘ip: "192.168.10.10"
memory: 2048
cpus: 1l
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/Code
      to: /home/vagrant/Code
      type: "nfs"

sites:
    - map: blog.dev
      to: /home/vagrant/Code/blog/public
      hhvm: true’

现在的状况是ssh可以正常登陆,已经执行了homestead up但是~/Code 的文件没有同步到homestead/home/vagrant/Code下面。

walterlize

BTW,没用成markdown,直接加 ’ '没实现,你使用的编译器。我刚下了个Mweb,稍后试试

JellyBool

markdown看一下这个吧 https://laravist.com/discussion/21 这样对双方都有好处 ,,貌似你的markdown都没有使用正确,我帮你修改了 @walterlize

JellyBool

首先将 type: "nfs"hhvm: true删掉,然后再 homestead provision试试

walterlize

@JellyBool 看到你的回复了,出去了一阵,现在跟您说一下我的尝试结果。
##新的尝试
您的laravel是5.1?我按照您的教程使用homestead还有有点问题。我搜到了http://v4.golaravel.com/docs/4.2/homestead
这个教程,跟您的教程大致类似,不过它是基于4.2版本。我按照教程还是出现了上文所述的错误。
##解决方案
后来,我还是按照官方文档进行了配置。http://www.golaravel.com/laravel/docs/5.1/homestead/
###关键步骤如下:
1、官网下载VirtualBox与vagrant(与本教程相同)
2、下载vagrant 的homestead box将其封装至Vagrant vagrant box add laravel/homestead
3、克隆homestead代码库至本地(本人就是一直未克隆,所以导致上述错误)
git clone https://github.com/laravel/homestead.git Homestead
然后执行Homestead目录 下的 bash init.sh 用以生产 Homestead.yaml文件,直接vi Homestead目录下的Homestead.yaml文件修改各项配置。
4、 Homestead 文件夹并执行vagrant up命令。

上述步骤是我亲测的,系统Mac OS,laravel版本5.1。谢谢楼主,以前用CI做过几个项目laravel是新学,还望遇到别的问题能跟楼主交流一下。

walterlize

@JellyBool 已支持,也是学生党,懂得其中艰辛,望写出更好的博文。

JellyBool

首先是非常感谢,然后就是刚刚录视频去了,没来得及时回复 。我的laravel是5.1版本,那你现在的问题解决了 ?@walterlize

Dikea 回复 JellyBool

很佩服你,浏览到这个帖子,很感兴趣JellyBool你现在每天是怎么安排自己时间的,怎么有这么多时间录视频,写博客

JellyBool 回复 Dikea

然而每天都是感觉时间不够用的啦

walterlize

对,解决了,我的也是5.1,按照上文贴出官方的步骤解决了。恩,就当是两种解决方案,稍后安装出问题的可以参考一下。

JellyBool

OK,说起来很奇怪,我直接使用官网的一行命令就可以了。。。 @walterlize

jeak84

按照教程安装后,开发目录已能同步,访问blog.dev,服务器给出的是“No input file specified.”,求教 !

xiao

homestead 按照教程配置好了,但总是连不上

jiji262

你好,请问教程里的动图是如何生成的?

yijiang

Homestead 这个下的也太久了下28小时 看到都心碎

JellyBool

凌晨一点到三点速度最快的了 @yijiang

JoeRChang

@jeak84 确定Homestead.yaml文件的sites路径没有错误,然后执行homestead provision,再homestead up就可以解决这个问题了,最近我也是遇到这个问题,博主的回复是正确的,感谢!

Anonymous

博主命令行工具用的什么,配色很赞。

Anonymous

用的是iTerm2 http://www.iterm2.com/

然后是oh-myzsh: http://ohmyz.sh/

Anonymous

1.composer源,可以使用以下命令添加国内的镜像
composer config -g repositories.packagist composer http://packagist.phpcomposer.com
2.homestead
不知道是不是Linux跟Mac的差别,我还需要执行以下几步才可以继续楼主的教程

在composer中激活homestead

composer global require "laravel/homestead=~2.0"

添加homestead到bin目录

ln -s ~/.composer/vendor/bin/homestead /usr/local/bin

homestead 初始化

homestead init

Anonymous

对于composer添加国内镜像,我还是会选择开vpn。

你安装的homestead是在Laravel 5.0 的版本?

Anonymous

是的。我是在vagrant安装玩homestead后使用homestead edit,提示没有homestead命令才google一下。发现
http://laravel.com/docs/4.2/homestead
提示可以1.With Composer + PHP Tool 2.Manually Via Git(No Local PHP) ,我选的是1
去翻看最新的文档
http://laravel.com/docs/5.1/homestead#first-steps
已经只有通过Cloning The Homestead Repository(git)方式了
但是好像在配置完vagrant之后都还有一步Installing Homestead才能使用homestead edit

Anonymous

没开vpn?那最后通过Cloning The Homestead Repository(git)方式用起来了没有?

Anonymous

vpn不影响吧?我的vagrant安装homestead通过代理的。
homestead edit成功运行是通过下面这个方法,应该跟git clone的基本没差
1.With Composer + PHP Tool
我不知道是Mac直接安装完就可以使用,还是以前安装过homestead所以不用再配置了
我已经在继续后面的教程了,楼主的教程写的很棒

Anonymous

OK,成功运行就好。有可能是我之前安装homestead的原因。但是安装官方5.1的文档来看,直接vagrant box add laravel/homestead就可以了。

不管怎样,问题解决了就好,Happy Hacking

Anonymous

博主,我在安装homestead 的时候choice了1后安装出现了问题

Enter your choice: 1
==> box: Adding box 'laravel/homestead' (v0.2.7) for provider: virtual
    box: Downloading: https://atlas.hashicorp.com/laravel/boxes/homest
ns/0.2.7/providers/virtualbox.box
==> box: Box download is resuming from prior download progress
    box: Progress: 0% (Rate: 0/s, Estimated time remaining: --:--:--)-
An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.

HTTP server doesn't seem to support byte ranges. Cannot resume.

请问该怎么解决

Anonymous

我永远都是建议开一个稳定的VPN

Anonymous

之前弄过一个不太好用,能给推荐一下么

Anonymous

homestead要使用composer安装,而安装composer中要选择php的路径,所以要先安装php,而homestead中也含有php,这不是重复了么

Anonymous

homestead是虚拟机,homestead的php是虚拟机的php,你安装composer时候安装的是你自己机器的虚拟机

Anonymous

[生病]我又有新的问题了,homestead up的时候报错

C:/Users/g150th/AppData/Roaming/Composer/vendor/laravel/homestead/scripts/homest
ead.rb:91:in `read': No such file or directory - C:/Users/g150th/.ssh/id_rsa.pub
 (Errno::ENOENT)
        from C:/Users/g150th/AppData/Roaming/Composer/vendor/laravel/homestead/s
cripts/homestead.rb:91:in `block in configure'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/plugins/kerne
l_v2/config/vm_provisioner.rb:72:in `call'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/plugins/kerne
l_v2/config/vm_provisioner.rb:72:in `add_config'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/plugins/kerne
l_v2/config/vm.rb:317:in `provision'
        from C:/Users/g150th/AppData/Roaming/Composer/vendor/laravel/homestead/s
cripts/homestead.rb:89:in `configure'
        from C:/Users/g150th/AppData/Roaming/Composer/vendor/laravel/homestead/V
agrantfile:20:in `block in <top (required)>'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/c
onfig/v2/loader.rb:37:in `call'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/c
onfig/v2/loader.rb:37:in `load'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/c
onfig/loader.rb:103:in `block (2 levels) in load'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/c
onfig/loader.rb:97:in `each'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/c
onfig/loader.rb:97:in `block in load'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/c
onfig/loader.rb:94:in `each'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/c
onfig/loader.rb:94:in `load'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/v
agrantfile.rb:28:in `initialize'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/e
nvironment.rb:689:in `new'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/e
nvironment.rb:689:in `vagrantfile'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/e
nvironment.rb:441:in `host'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/e
nvironment.rb:207:in `block in action_runner'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/runner.rb:33:in `call'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/a
ction/runner.rb:33:in `run'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/e
nvironment.rb:428:in `hook'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/e
nvironment.rb:671:in `unload'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/bin/vagrant:1
77:in `ensure in <main>'
        from E:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/bin/vagrant:1
77:in `<main>'

网上找了好久也不知道怎么解决

Anonymous

把你的homestead.yaml给我看一下,你可以到这里来问我。

https://laravist.com/discuss
这里我会回答得快一点

Anonymous
authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: E:/php_code
      to: /home/vagrant/Code

sites:
    - map: blog.dev
      to: /home/vagrant/Code/Laravel/public

databases:
    - homestead

variables:
    - key: APP_ENV
      value: local

楼主帮我看一看,是因为我没有设置ssh么

Anonymous

你好博主,我就住在川大对面,不过我已经工作了,平时用的java,现在有一些项目,所以我想学习一下laravel,主要是因为他的开发效率,之前也一直纠结时rails还是laravel,后来想想,还是…………一起吧。近期准备先学习一下laravel,If something block me, I hope you can help me, Thanks~~

Anonymous

国内composer太慢了,还是去go-laravel.com直接下载安装包快,各种包都打包在一块了

Anonymous

要想愉快使用laravel,composer必然离不开

Anonymous

我也遇到了同样的问题,
请问这个问题该如何解决?

Anonymous

估计就是路径没对吧

Anonymous

为什么我配置号后 浏览器http://homestead.app/ 只是出现Bad Gateway?
而且在虚拟机中 vagrant@homestead:~$ ls 什么也没有出现?

Anonymous

没配置对吧

Anonymous

虽然没有强迫症,但是看着很难受:
启动服务的三个选择:1. 1. 1.
另外很喜欢你的博客和视频。

Anonymous

安装完Laravel之后,我们怎么使用呢?也就是我们怎么在浏览器中输入相对应得url来访问到我们的Laravel呢?这里你有三个选择:
notice:声明了三个选择,却只定义了一个。

pepsihumen

这个是我的配置:无法访问到虚拟机,Host里面已经设置,虚拟机正常启动

PHP方式启动正常

Mac10.12

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

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/home/vagrant/Code/Laravel/blog
      to: /home/vagrant/Code
sites:
    - map: blog.dev
      to: /home/vagrant/Code/blog/public

databases:
    - homestead

# blackfire:
#     - id: foo
#       token: bar
#       client-id: foo
#       client-token: bar

# ports:
#     - send: 50000
#       to: 5000
#     - send: 7777
#       to: 777
#       protocol: udp
hehorange

赞,这是我看到目前最通俗易懂的教程了,官方文档看起来有些生涩,其他教程在细节方面有时缺乏解释,新手就卡住了。本来想尝试一下homestead的,但我的机子一开虚拟机就卡死,不知道为什么,哎,学生党,攒钱买mac。祝网站越办越好

zyzplzyz

群主,问下honestead能部署除了laravel以为其他的php框架吗

JellyBool 回复 zyzplzyz

Homestead 是一个虚拟机(Ubuntu),部署什么 php 框架都是可以的吧。你自己设置就好,就跟设置你的 VPS 一样啊

zyzplzyz 回复 JellyBool

好的,我明白了,谢谢了,群主的回答

kokobin

迷上了!迷上了!

xiangxihenli

学习了。。。。

jayin
1) parallels
2) virtualbox
3) vmware_desktop

Enter your choice: 2
==> box: Adding box 'laravel/homestead' (v2.1.0) for provider: virtualbox
    box: Downloading: https://atlas.hashicorp.com/laravel/boxes/homestead/versions/2.1.0/providers/virtualbox.box
    box:
An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.

Failed to connect to hc-prod-storagelocker.s3.amazonaws.com port 443: Timed out

我是win10

JellyBool 回复 jayin

这个需要一个好的梯子

jayin 回复 JellyBool

开了vpn,这个是国外哪条线

soyoung 回复 jayin

跟你一样的问题,怎么解决?

jayin

@TimelsGoOn 能不能帮我看一下

xuzan@MSI MINGW64 ~/Desktop/Homestead (master)
$ vagrant up
C:/Users/xuzan/Desktop/Homestead/scripts/homestead.rb:118:in `read': No such fil                                                                                                                                  e or directory @ rb_sysopen - C:/Users/xuzan/.ssh/id_rsa (Errno::ENOENT)
        from C:/Users/xuzan/Desktop/Homestead/scripts/homestead.rb:118:in `block                                                                                                                                   (2 levels) in configure'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/plugins/kerne                                                                                                                                  l_v2/config/vm_provisioner.rb:72:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/plugins/kerne                                                                                                                                  l_v2/config/vm_provisioner.rb:72:in `add_config'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/plugins/kerne                                                                                                                                  l_v2/config/vm.rb:338:in `provision'
        from C:/Users/xuzan/Desktop/Homestead/scripts/homestead.rb:115:in `block                                                                                                                                   in configure'
        from C:/Users/xuzan/Desktop/Homestead/scripts/homestead.rb:114:in `each'
        from C:/Users/xuzan/Desktop/Homestead/scripts/homestead.rb:114:in `confi                                                                                                                                  gure'
        from C:/Users/xuzan/Desktop/Homestead/Vagrantfile:35:in `block in <top (                                                                                                                                  required)>'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/c                                                                                                                                  onfig/v2/loader.rb:37:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/c                                                                                                                                  onfig/v2/loader.rb:37:in `load'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/c                                                                                                                                  onfig/loader.rb:113:in `block (2 levels) in load'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/c                                                                                                                                  onfig/loader.rb:107:in `each'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/c                                                                                                                                  onfig/loader.rb:107:in `block in load'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/c                                                                                                                                  onfig/loader.rb:104:in `each'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/c                                                                                                                                  onfig/loader.rb:104:in `load'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/v                                                                                                                                  agrantfile.rb:28:in `initialize'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/e                                                                                                                                  nvironment.rb:746:in `new'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/e                                                                                                                                  nvironment.rb:746:in `vagrantfile'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/e                                                                                                                                  nvironment.rb:492:in `host'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/e                                                                                                                                  nvironment.rb:214:in `block in action_runner'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/a                                                                                                                                  ction/runner.rb:33:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/a                                                                                                                                  ction/runner.rb:33:in `run'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/e                                                                                                                                  nvironment.rb:479:in `hook'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/lib/vagrant/e                                                                                                                                  nvironment.rb:728:in `unload'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/bin/vagrant:1                                                                                                                                  41:in `ensure in <main>'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.5/bin/vagrant:1                                                                                                                                  41:in `<main>'

我对搭环境有点弱

JellyBool 回复 jayin

这个感觉是文件没完整或者你的 ruby 环境有问题

jayin 回复 JellyBool
xuzan@MSI MINGW64 ~/Homestead (master)
$ vagrant box add laravel/homestead E:/homestead/homestead.box --force
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'laravel/homestead' (v0) for provider:
    box: Unpacking necessary files from: file:///E:/homestead/homestead.box
    box:
==> box: Successfully added box 'laravel/homestead' (v0) for 'virtualbox'!

xuzan@MSI MINGW64 ~/Homestead (master)
$ homestead
bash: homestead: command not found

xuzan@MSI MINGW64 ~/Homestead (master)
jayin

homestead up命名not found?

fighting 回复 jayin

这个命令无效是什么原因?

jayin

花了一天终于搭建好了,google,百度,各种查看,以前就是怕搭搭建环境,但是我觉得还是有必要入这个坑

xuzan@MSI MINGW64 ~/Homestead (master)
$ vagrant ssh
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-66-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

3 packages can be updated.
0 updates are security updates.


vagrant@homestead:~$ ls
Code
vagrant@homestead:~$ cd
vagrant@homestead:~$ ls
Code
vagrant@homestead:~$ cd Code/
vagrant@homestead:~/Code$ ls
Api  app  artisan  bootstrap  composer.json  composer.lock  config  database  gulpfile.js  package.json  phpunit.xml  public  readme.md  resources  server.php  storage  tests  vendor
vagrant@homestead:~/Code$ cd
vagrant@homestead:~$ ls
Code
vagrant@homestead:~$ cd
vagrant@homestead:~$

window用户搭建homestead可以@我,毕竟我从这个坑走过来 ,HAHA

soyoung 回复 jayin

求指教啊 各种报错 @jayin

An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.
我有vpn啊,这应该不是网络问题吧

jayin 回复 soyoung

我百度云盘分享哪个virtualbox.box给你,直接外挂方式,不要去下载了,下了几个小时
##链接:http://pan.baidu.com/s/1eRVwdfc 密码:yawq
参考链接:https://laravel-china.org/topics/2519/how-to-install-laravel-windows-on-homestead

soyoung 回复 jayin

感恩!windows坑真的好多

X氵丿米丨

屏幕快照 2017-06-01 下午9.27.58.png
之前安装没有成功,再次安装就一直报这个错误。怎么解决?

X氵丿米丨

![截图](/Users/chaly/Desktop/屏幕快照 2017-06-01 下午9.27.58.png)
之前安装没有成功,再次安装就一直报这个错误。怎么解决?

bearyuan

试一下回复功能不能正常使用

bearyuan

用lamp行不咯?

bearyuan

为啥我评论没用代码高亮模式??????????

bearyuan

你这里有问题哦。评论,会自动产生好几条

bearyuan

测试一下回复功能不能正常使用