songjiaxin2008
V2EX  ›  PHP

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

  •  
  •   songjiaxin2008 · Apr 25, 2016 · 8031 views
    This topic created in 3844 days ago, the information mentioned may be changed or developed.
    因为不支持全文转载,所以直接贴出链接,希望可以帮助初学者,欢迎指正 :)
    https://solarhell.com/post/2016/04/homestead
    Supplement 1  ·  Apr 26, 2016
    可以 alias 一条命令来快速 ssh 进入开发环境
    ssh [email protected] -p 2222 -i ~/.vagrant.d/insecure_private_key
    40 replies  •  2016-05-10 13:59:50 +08:00
    Magician
    Magician
    Apr 25, 2016
    1
    然后你会发现 打开你的 homestead.app 会出现 502
    songjiaxin2008
    songjiaxin2008
    OP
    Apr 25, 2016
    2
    @Magician 不会呀 0.0
    Magician
    Magician
    Apr 25, 2016
    3
    楼主是个坑货 为什么不 讲一下那个 /etc/nginx/sites-enabled/ 那个 php5 要改成 php7.0
    Magician
    Magician
    Apr 25, 2016
    4
    你这个是 php5.6 啊
    songjiaxin2008
    songjiaxin2008
    OP
    Apr 25, 2016
    5
    @Magician 不不不 不用配置的 默认就是 php7-fpm
    songjiaxin2008
    songjiaxin2008
    OP
    Apr 25, 2016
    6
    Magician
    Magician
    Apr 25, 2016
    7
    @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
    songjiaxin2008
    OP
    Apr 25, 2016
    8
    运行 vagrant box list 后,我的输出是 laravel/homestead (virtualbox, 0.4.4) 。或许你的 box 版本旧一点?
    Magician
    Magician
    Apr 25, 2016
    9
    ☁ manage vagrant box list
    laravel/homestead (virtualbox, 0) 我的是这个呢
    lissome
    lissome
    Apr 25, 2016
    10
    @Magician
    这个应该不是用官方源添加的 box ,估计是旧版本的
    songjiaxin2008
    songjiaxin2008
    OP
    Apr 25, 2016 via iPhone
    11
    @Magician 你这个是手动下载添加的吗
    isCyan
    isCyan
    Apr 25, 2016 via iPhone
    12
    最新的 0.4.4
    http://ws.penbeat.cn/laravel-homestead/0.4.4/virtualbox.box
    这是七牛存储下载,我从我的美国 VPS 传到七牛的。
    songjiaxin2008
    songjiaxin2008
    OP
    Apr 25, 2016
    13
    @isCyan 感谢。我拜托过教育网的同学帮我下载过,确实能正确执行 vagrant box add xxx.box 但是 homestead 不认--
    isCyan
    isCyan
    Apr 25, 2016 via iPhone
    14
    @songjiaxin2008 那该怎么办?等它几十 KB 的速度?我这似乎也是不认,我以为是操作不对。
    lujjjh
    lujjjh
    Apr 25, 2016❤️2
    15
    @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
    Magician
    Apr 25, 2016
    16
    @songjiaxin2008 我把箱子弄到 美国的 VPS 上的 弄到本地 加上的
    Light3
    Light3
    Apr 25, 2016
    17
    想弄过 不过网速不行阿 你既然下过了 你不弄个网盘分享下。。= =
    songjiaxin2008
    songjiaxin2008
    OP
    Apr 25, 2016
    18
    @lujjjh 感谢 马上更新到文章里
    pengbo37877
    pengbo37877
    Apr 25, 2016
    19
    今天才被这个配置坑过
    songjiaxin2008
    songjiaxin2008
    OP
    Apr 25, 2016
    20
    @pengbo37877 对 所以写在博客备忘
    fhefh
    fhefh
    Apr 25, 2016
    21
    看了楼主的博客 给 folder 加了 type : nfs 打开雅黑探针速度嗖嗖的
    之前安装好环境后 用雅黑探针 感觉好慢
    xiaonianji
    xiaonianji
    Apr 25, 2016
    22
    @isCyan 多谢分享,正愁这个呢哈哈哈
    Magician
    Magician
    Apr 25, 2016
    23
    用国外的服务器下好 每秒 1MB 的速度拉到本地 感觉不错
    DesignerSkyline
    DesignerSkyline
    Apr 25, 2016
    24
    嗯,我爱 Homestead 这个单词,感觉瞬间眼前有种田园风
    songjiaxin2008
    songjiaxin2008
    OP
    Apr 25, 2016
    25
    @fhefh 一定是 Mac !
    @DesignerSkyline 你的域名单词也很不错! bismarck 很酷的那种
    DesignerSkyline
    DesignerSkyline
    Apr 25, 2016
    26
    @songjiaxin2008 不不不, bismarck.moe 只是因为舰娘里的俾斯麦才买的。。。
    Nixus
    Nixus
    Apr 26, 2016
    27
    我觉得,我在折腾技术的过程中,很大一部分时间都花在了翻墙上!!!
    GFW 谋财害命!!!
    Nixus
    Nixus
    Apr 26, 2016
    28
    @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
    songjiaxin2008
    OP
    Apr 26, 2016❤️1
    29
    @Nixus 是因为 G*W 吧,我是挂的日本 SS (你看我截图也是尝试了好几次都失败)。前面几楼有朋友下载了镜像,你可以通过那个链接下载再来,再手动创建 metadata.json ,也是完美添加。
    Nixus
    Nixus
    Apr 26, 2016
    30
    @songjiaxin2008 网络问题,试了好几次终于可以了!谢谢!不过还是不怎么清楚怎么用!只能用 laravel 吗?还是只要是 php ,就可以用?
    quericy
    quericy
    Apr 26, 2016
    31
    @lujjjh 感谢分享,之前我用 init 来初始化,然后用默认的 Vagrantfile 文件 up 了展开,再替换回 homestead 的 Vagrantfile 文件,但是这个方法一直不完美...

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

    按照这个安装步骤有遗漏嘛
    http://laravelacademy.org/post/2749.html
    songjiaxin2008
    songjiaxin2008
    OP
    Apr 27, 2016
    36
    @allstand 一样的步骤 你可以手动配置一下 或许没能自动创建好项目
    xiaonianji
    xiaonianji
    Apr 28, 2016
    37
    为什么是 7.0 啊,我想用 5.5 的怎么办
    songjiaxin2008
    songjiaxin2008
    OP
    Apr 29, 2016 via iPhone
    38
    @xiaonianji 有人打包了这样的 vagrant box 搜索看一下
    nuc093
    nuc093
    May 10, 2016
    39
    @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
    xiaonianji
    May 10, 2016
    40
    @nuc093 3Q ,已 star ,抽空折腾下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5297 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 76ms · UTC 01:27 · PVG 09:27 · LAX 17:27 · JFK 20:27
    ♥ Do have faith in what you're doing.