文章目录
前言
我手里的项目,为了测试方便,将homestead的配置文件也一并放到了项目根目录下。因此,所有的操作,都是基于项目根目录下的。一、启动HomeStead
1. 下载HomeStead镜像
1.1 镜像下载地址前文有写,现在已经更新到了12.0.0
https://vagrantcloud.com/laravel/boxes/homestead/versions/
下载到本地,使用同样的方式导入到Vagrant中
1.2 因为新项目只将配置文件上传了Git,所以这里需要重新下载HomeStead需要的脚本
直接使用Composer即可,顺便也就将Laravel的依赖给下载好了。
Bash: composer update
1.3 此时启动vagrant up, 发现竟然找不到我们刚导入的12.0.0版本镜像,原因是这个文件的代码没有更新
homestead.rb:
config.vm.box_version = settings['version'] ||= '>= 11.0.0, < 12.0.0'
将后面的判断代码改成<=12.0.0,重新vagrant up,问题解决!
到此,HomeStead的虚拟机便可以正常启动
2. 配置HomeStead镜像
修改Homestead.yaml
ip: 192.168.10.10
map: homestead.win
to: /home/vagrant/Laravel/WebFor5G/code/public
php: '8.0'
这里做的更改是为了设定Nginx的Server目录和相应IP,以及对应的php-fpm版本。
设置结束,直接网页登陆192.168.10.10,看看效果:
**网页访问报错502**
。。。
查看Nginx Error Log:
# tail -f /var/log/nginx/homestead.win-error.log
connect() to unix:/var/run/php/php8.0-fpm.sock failed (2: No such file or directory)
原因:因为图新鲜,用了12.0.0的Homestead镜像,默认的fpm版本是8.1的。
有两种修复方式:
a. 将错就错,提升Ngnix的php版本为8.1----php: '8.1'
**实际不可行**,因为8.1的语法取消了一些向下兼容,Laravel8.0会引发如下报警:
FastCGI sent in stderr: "PHP message: PHP Deprecated: Return type of Illuminate\Http\Request::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/vagrant/Laravel/WebFor5G/code/vendor/laravel/framework/src/Illuminate/Http/Request.php on line 651
b. 继续使用8.0版本的php-fpm:
update-alternatives --config php (具体流程截图在下方)
service php8.0-fpm restart
用回php-fpm8.0之后,重新登陆192.168.10.10,已经可以看到正常的DB报错了:
Table 'homestead.sessions' doesn't exist
这个是因为我们还没有迁移DB,按照前文操作即可!
php artisan migrate
HomeStead配置完毕!
二、启用Docker
1.
2.
Docker就此配置完毕
总结
新机器+老项目,最重要的步骤是根据项目的配置文件download各种库和依赖:
composer.json 决定后端PHP框架需要的所有依赖,对应vendor目录:
基本命令:composer install
package.json 决定前端JS框架需要的所有依赖,对应node-modules目录:
基本命令:npm install