1.应用场景
主要用于搭建开发环境,很省事,尽管存在一些缺点。但是在适度之内即可,权衡问题。 |
2. 学习/实践
前言整个过程参考 // 2019.1.9 周三 春风路3007号
1.环境
2.建议将vagrant 和 virtualbox升级到最新(稳定)版, 避免接下来出现的各种问题. 3.在开发机(个人电脑)上,干净的地方,新建一个文件夹,如:D:\vagarant-lumen 4.将box放到D:\vagarant-lumen 目录下
具体操作,这里暂不详述. 应涉及到源码编译 或者[听说国外常这么干] 直接打开连接下载: https://app.vagrantup.com/laravel/boxes/homestead/versions/6.3.0/providers/virtualbox.box 上面的6.3.0是版本号,可以修改为指定的版本号.下载完之后,可能需要进行手动更名. 名字要和自己后续使用的名字保持一致,此处更名为: homestead-virtualbox-6.3.0.box 5.在D:\vagarant-lumen中新建metadata.json文件metadata.json内容如下:Note: version, url对应的值, 要跟真实情况保持一致. 6. 安装 Homestead Vagrant Box进入到D:\vagarant-lumen,打开cmd或者gitbash, 输入:vagrant box add metadata.jsonNote: vagrant box add laravel/homestead 是用从线上[vagrant开源社区]下载最新版box. -------------TBD简单补充: 添加box到本地仓库: https://blog.csdn.net/zsl10/article/details/51997367 7.查看是否添加成功vagrant box list // 因为vagrant 是全局安装,所以此命令不用进入到指定目录下,但是建议,统一进入到指定目录下,必然是没有问题的.又不是比赛.有时费时省力,未尝不可,而且未必以后一直是费时的[个人看法]8.安装 Homestead①通过克隆代码来安装 Homestead,可以使用http方式或者ssh方式这里使用的是ssh方式,因为http方式一直有问题,原因暂时不清,也没有解决.git clone [email protected]:laravel/homestead.git ②开始进入homestead目录下因为 Homestead 的 master 分支并不是稳定分支,应该使用打过标签的稳定版本。 可以在GitHub发行页[https://github.com/laravel/homestead/releases]上找到最新的稳定版本,这里推荐使用v7.19.2 ③git checkout v7.19.2④$ bash init.shHomestead initialized! ⑤此时homestead目录下,会生成几个文件,只需要关注Homestead.yaml即可打开Homestead.yaml 熟悉里面的配置项 --- 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 # blackfire: # - id: foo # token: bar # client-id: foo # client-token: bar # ports: # - send: 50000 # to: 5000 # - send: 7777 # to: 777 # protocol: udp 详情参见: https://laravel-china.org/docs/laravel/5.6/homestead/1355 ⑥修改windows host 文件 C:/Windows/System32/Drivers/etc/hosts192.168.10.10 homestead.app Note: 如果修改不了,请把hosts文件拖到桌面,修改保存,再拖回原来的目录下. ⑦在homestead目录下,执行vagrant up Note : homestead虚拟机的配置都在 :D:\vagarant-lumen\homestead\scripts\homestead.rb文件中,详细参见文件 9.看Homestead.yaml 我们发现只需将Laravel或者lumen的代码放到homestead同级目录的code文件夹即可Note: 在windows下,并不是这样的,因为 folders: - map: ~/code to: /home/vagrant/code ~/code 表示的是 C:\Users\william_ning\code 所以需要在C:\Users\william_ning目录下新建文件夹code. 或者 将- map: ~/code修改为/d/vagarant-lumen/homestead/code ---------------TBD 10.进入到code目录下[这里是C:\Users\william_ning\code],新建public目录,并在内新建index.php index.php内容如下: <?php phpinfo(); 11.测试环境是否ok浏览器中输入:localhost:8000如下: 表示环境已经成功.填坑
①vagrant up之后提示信息: ” can't read /etc/php/7.2/fpm/pool.d/www.conf: No such file or directoryThe SSH command responded with a non-zero exit status.” 解决思路参考: a.vagrant reload //重启虚拟机,查看是否仍有上述问题. b.参考 https://github.com/hashicorp/vagrant/issues/1659 ②有时目录挂载不成功解决思路:
③输入localhost:8000
④浏览器中输入:
均没有响应, 原因是公司代理的问题,导致不能使用虚拟主机设置.对于开发不是必须.所以可以选择跳过 但是首先,要确定能访问到虚拟机: 保证能访问到,之后 解决办法: 设置代理 a.添加192.168.*.* 和homestead.test Firefox 代理设置如下: Chrome[使用代理插件swichyOmega] 代理设置如下: keyon IE 代理设置如下: Homestead.test 有些问题,应该跟ie浏览器本身的设置和实现有关,具体不再研究. ---------------------------------------------------------------分割线------------------------------------------------------------------------ 进入code目录下,clone code git clone [email protected]:laravel/lumen.git 12.运行lumen / laravel framework // TBD
----------------------------------------------------------------分割线-------------------------------------------------------------------- Centos nginx重启 重启Nginx service nginx restart /etc/init.d/nginx stop /etc/init.d/nginx start Ubuntu Nginx $sudo service nginx start $sudo service nginx stop win7 启动 解压至c:\nginx,运行nginx.exe(即nginx -c conf\nginx.conf),默认使用80端口,日志见文件夹C:\nginx\logs 常用配置 C:\nginx\conf\nginx.conf,使用自己定义的conf文件如my.conf,命令为nginx -c conf\my.conf 方便有用的linux命令: cd .. //返回上级目录 cd – //返回上一次目录 |
3.问题/补充
1. 尽管虚拟机中,显示PHP版本为8.0,但是具体的项目使用的还是指定的版本2. homestead虚拟机中vagrant用户密码,以及如何使用root权限https://learnku.com/laravel/wikis/37099 3. 访问web页面出现502 Bad Gateway... connect() to unix:/var/run/php/php7.2-fpm.sock failed ...原因和解决办法: https://stackoverflow.com/questions/51158830/nginx-connect-to-unix-var-run-php7-2-fpm-sock-failed-2-no-such-file-or-dir/51159313
4. 关于homestead的各种操作命令... |
4.参考
https://www.vagrantup.com/ https://app.vagrantup.com/boxes/search?utf8=%E2%9C%93&sort=downloads&provider=&q=homestead // 寻找box https://app.vagrantup.com/laravel/boxes/homestead/versions/6.3.0/providers/virtualbox.box // 直接下载box,可以将版本号做调整 https://www.cnblogs.com/zero-zf/p/6031965.html // 安装教程 https://my.oschina.net/cxgphper/blog/1940644 https://blog.csdn.net/min903245074/article/details/77954857 https://pan.baidu.com/s/1eRLsJ42#list/path=%2F https://laravel-china.org/articles/7369/im-climbing-out-of-the-homestead-pit-for-the-development-of-the-environment https://laravel-china.org/topics/4796/ssh-auth-method-private-key-solution-summary-when-homestead-startshttp:// https://laravel-china.org/docs/laravel/5.6/homestead/1355 https://github.com/laravel/homestead https://laravel-china.org/docs/lumen/5.6 https://laravel-china.org/docs/lumen/5.6/install/1924 https://github.com/search?q=lumen https://github.com/laravel/lumen https://github.com/laravel https://github.com/ningxiaofa/homestead https://laravel.com/docs/5.7/homestead https://blog.csdn.net/min903245074/article/details/77954857 // Homestead安装大法和总结一些坑 https://laravel-china.org/articles/7369/im-climbing-out-of-the-homestead-pit-for-the-development-of-the-environment // 开发环境部署之 Homestead 大坑,我是这样爬出来的 https://laravel-china.org/topics/4796/ssh-auth-method-private-key-solution-summary-when-homestead-startshttp:// // Homestead 安装问题汇总 https://laravel-china.org/articles/4668/why-do-you-have-to-use-homestead-to-develop-laravel-applications //为什么必须使用 Homestead 来开发 Laravel 应用? https://blog.csdn.net/min903245074/article/details/77954857 // Homestead安装大法和总结一些坑 https://github.com/laravel/homestead // 源码 https://laravel.com/docs/8.x/homestead // 官网文档 |
后续补充
...