使用 Homestead 来打造舒适的开发环境 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
songjiaxin2008
V2EX    PHP

使用 Homestead 来打造舒适的开发环境

  •  
  •   songjiaxin2008 2016-04-25 11:30:08 +08:00 7323 次点击
    这是一个创建于 3488 天前的主题,其中的信息可能已经有所发展或是发生改变。
    因为不支持全文转载,所以直接贴出链接,希望可以帮助初学者,欢迎指正 :)
    https://solarhell.com/post/2016/04/homestead
    第 1 条附言    2016-04-26 16:11:01 +08:00
    可以 alias 一条命令来快速 ssh 进入开发环境
    ssh [email protected] -p 2222 -i ~/.vagrant.d/insecure_private_key
    40 条回复    2016-05-10 13:59:50 +08:00
    Magician
        1
    Magician  
       2016-04-25 11:32:15 +08:00
    然后你会发现 打开你的 homestead.app 会出现 502
    songjiaxin2008
        2
    songjiaxin2008  
    OP
       2016-04-25 11:33:17 +08:00
    @Magician 不会呀 0.0
    Magician
        3
    Magician  
       2016-04-25 11:33:53 +08:00
    楼主是个坑货 为什么不 讲一下那个 /etc/nginx/sites-enabled/ 那个 php5 要改成 php7.0
    Magician
        4
    Magician  
       2016-04-25 11:34:25 +08:00
    你这个是 php5.6 啊
    songjiaxin2008
        5
    songjiaxin2008  
    OP
       2016-04-25 11:35:49 +08:00
    @Magician 不不不 不用配置的 默认就是 php7-fpm
    songjiaxin2008
        6
    songjiaxin2008  
    OP
       2016-04-25 11:36:34 +08:00
    Magician
        7
    Magician  
       2016-04-25 11:40:46 +08:00
    @songjiaxin2008 我装好后是

    root@homestead:/etc/nginx/sites-enabled# cat homestead.app
    server {
    listen 80;
    listen 443 ssl;
    server_name homestead.app;
    root "/home/vagrant/Projects/laravel/public";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
    try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt { access_log off; log_not_found off; }

    access_log off;
    error_log /var/log/nginx/homestead.app-error.log error;

    sendfile off;

    client_max_body_size 100m;

    location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors off;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    }

    location ~ /\.ht {
    deny all;
    }

    ssl_certificate /etc/nginx/ssl/homestead.app.crt;
    ssl_certificate_key /etc/nginx/ssl/homestead.app.key;
    }
    songjiaxin2008
        8
    songjiaxin2008  
    OP
       2016-04-25 11:42:26 +08:00
    运行 vagrant box list 后,我的输出是 laravel/homestead (virtualbox, 0.4.4) 。或许你的 box 版本旧一点?
    Magician
        9
    Magician  
       2016-04-25 11:43:19 +08:00
    manage vagrant box list
    laravel/homestead (virtualbox, 0) 我的是这个呢
    lissome
        10
    lissome  
       2016-04-25 12:05:06 +08:00
    @Magician
    这个应该不是用官方源添加的 box ,估计是旧版本的
    songjiaxin2008
        11
    songjiaxin2008  
    OP
       2016-04-25 12:17:52 +08:00 via iPhone
    @Magician 你这个是手动下载添加的吗
    isCyan
        12
    isCyan  
       2016-04-25 12:28:02 +08:00 via iPhone
    最新的 0.4.4
    http://ws.penbeat.cn/laravel-homestead/0.4.4/virtualbox.box
    这是七牛存储下载,我从我的美国 VPS 传到七牛的。
    songjiaxin2008
        13
    songjiaxin2008  
    OP
       2016-04-25 12:29:21 +08:00
    @isCyan 感谢。我拜托过教育网的同学帮我下载过,确实能正确执行 vagrant box add xxx.box 但是 homestead 不认--
    isCyan
        14
    isCyan  
       2016-04-25 12:35:26 +08:00 via iPhone
    @songjiaxin2008 那该怎么办?等它几十 KB 的速度?我这似乎也是不认,我以为是操作不对。
    lujjjh
        15
    lujjjh  
       2016-04-25 12:51:43 +08:00   2
    @songjiaxin2008
    @isCyan

    Homestead 对 box 的版本号有要求(>= 0.4.0 ),手动添加的 box 的版本号是 0 (下载下来的 box 文件不含 metadata ),所以会出问题。

    解决方法就是创建一个 metadata.json 文件指明 box 的版本号,具体可以看这里:

    http://stackoverflow.com/questions/34946837/box-laravel-homestead-could-not-be-found
    Magician
        16
    Magician  
       2016-04-25 13:11:43 +08:00
    @songjiaxin2008 我把箱子弄到 美国的 VPS 上的 弄到本地 加上的
    Light3
        17
    Light3  
       2016-04-25 14:01:10 +08:00
    想弄过 不过网速不行阿 你既然下过了 你不弄个网盘分享下。。= =
    songjiaxin2008
        18
    songjiaxin2008  
    OP
       2016-04-25 14:01:16 +08:00
    @lujjjh 感谢 马上更新到文章里
    pengbo37877
        19
    pengbo37877  
       2016-04-25 18:30:49 +08:00
    今天才被这个配置坑过
    songjiaxin2008
        20
    songjiaxin2008  
    OP
       2016-04-25 18:48:21 +08:00
    @pengbo37877 对 所以写在博客备忘
    fhefh
        21
    fhefh  
       2016-04-25 19:24:55 +08:00
    看了楼主的博客 给 folder 加了 type : nfs 打开雅黑探针速度嗖嗖的
    之前安装好环境后 用雅黑探针 感觉好慢
    xiaonianji
        22
    xiaonianji  
       2016-04-25 21:31:26 +08:00
    @isCyan 多谢分享,正愁这个呢哈哈哈
    Magician
        23
    Magician  
       2016-04-25 21:33:25 +08:00
    用国外的服务器下好 每秒 1MB 的速度拉到本地 感觉不错
    DesignerSkyline
        24
    DesignerSkyline  
       2016-04-25 21:49:41 +08:00
    嗯,我爱 Homestead 这个单词,感觉瞬间眼前有种田园风
    songjiaxin2008
        25
    songjiaxin2008  
    OP
       2016-04-25 22:17:28 +08:00
    @fhefh 一定是 Mac !
    @DesignerSkyline 你的域名单词也很不错! bismarck 很酷的那种
    DesignerSkyline
        26
    DesignerSkyline  
       2016-04-25 22:21:35 +08:00
    @songjiaxin2008 不不不, bismarck.moe 只是因为舰娘里的俾斯麦才买的。。。
    Nixus
        27
    Nixus  
       2016-04-26 07:29:43 +08:00
    我觉得,我在折腾技术的过程中,很大一部分时间都花在了翻墙上!!!
    GFW 谋财害命!!!
    Nixus
        28
    Nixus  
       2016-04-26 10:34:49 +08:00
    @songjiaxin2008 请问你用的什么梯子?尝试了多次,都报错
    An error occurred while downloading the remote file. The error
    message, if any, is reproduced below. Please fix this error and try
    again.

    SSL read: error:00000000:lib(0):func(0):reason(0), errno 60

    搜了一下,有个说,换一个好的网络。真的是网络问题?
    songjiaxin2008
        29
    songjiaxin2008  
    OP
       2016-04-26 10:38:27 +08:00   1
    @Nixus 是因为 G*W 吧,我是挂的日本 SS (你看我截图也是尝试了好几次都失败)。前面几楼有朋友下载了镜像,你可以通过那个链接下载再来,再手动创建 metadata.json ,也是完美添加。
    Nixus
        30
    Nixus  
       2016-04-26 15:11:18 +08:00
    @songjiaxin2008 网络问题,试了好几次终于可以了!谢谢!不过还是不怎么清楚怎么用!只能用 laravel 吗?还是只要是 php ,就可以用?
    quericy
        31
    quericy  
       2016-04-26 15:13:34 +08:00
    @lujjjh 感谢分享,之前我用 init 来初始化,然后用默认的 Vagrantfile 文件 up 了展开,再替换回 homestead 的 Vagrantfil 文件,但是这个方法一直不完美...

    如果能早点看到就好了
    songjiaxin2008
        32
    songjiaxin2008  
    OP
       2016-04-26 15:29:28 +08:00   1
    @Nixus 都可以(也可以开发 node 程序),程序放在 Code 这个目录里面,在本机开 IDE 开发,然后注意配置下 nginx 里的程序目录就可以了。
    Nixus
        33
    Nixus  
       2016-04-26 16:01:45 +08:00
    @songjiaxin2008 就是开发什么,就在里面配置什么,对吗?非常感谢!
    songjiaxin2008
        34
    songjiaxin2008  
    OP
       2016-04-26 16:05:50 +08:00
    @Nixus 嗯,只要注意修改下默认的 /etc/nginx/sites-enabled/ 里面的配置文件,甚至可以添加多个域名。
    allstand
        35
    allstand  
       2016-04-27 21:51:59 +08:00
    为什么配置完了之后,虚拟机的 /home/vagrant/Code/里,没有 Laravel/public 路径呢?
    Nginx.conf 里也没有生成像你们上面贴的内容。

    按照这个安装步骤有遗漏嘛
    http://laravelacademy.org/post/2749.html
    songjiaxin2008
        36
    songjiaxin2008  
    OP
       2016-04-27 22:41:24 +08:00
    @allstand 一样的步骤 你可以手动配置一下 或许没能自动创建好项目
    xiaonianji
        37
    xiaonianji  
       2016-04-28 16:30:02 +08:00
    为什么是 7.0 啊,我想用 5.5 的怎么办
    songjiaxin2008
        38
    songjiaxin2008  
    OP
       2016-04-29 14:03:20 +08:00 via iPhone
    @xiaonianji 有人打包了这样的 vagrant box 搜索看一下
    nuc093
        39
    nuc093  
       2016-05-10 12:33:51 +08:00
    @xiaonianji 有个 5.6 的

    PHP56 Instead of PHP7 in Laravel Homestead

    https://github.com/gjrdiesel/homestead56.git

    部分 readme 操作步骤

    Copy Sites From Original Homestead

    git clone https://github.com/gjrdiesel/homestead.git ~/Homestead56

    cd ~/Homestead56; cp -rv ~/.homestead/ ~/.homestead-56/; vagrant up

    试用了一下可以和官方的 homestead 灵活切换。具体操作见该项目 readme
    xiaonianji
        40
    xiaonianji  
       2016-05-10 13:59:50 +08:00
    @nuc093 3Q ,已 star ,抽空折腾下
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2965 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 45ms UTC 12:51 PVG 20:51 LAX 04:51 JFK 07:51
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86