记一次迁移PHP项目composer安装依赖报错的问题

发布于 2024-03-20  470 次阅读


内容纲要

由于更换服务器需要迁移一个PHP项目,通过Github保存了源代码,但是在.gitignore中存在将/vendor忽略了,因此在项目迁移之后需要重新通过composer安装依赖。

刚开始迁移的时候没有注意,打开中间价文件报错:

public function handle($request, \Closure $next)
    {
        // 判断参数
        $result = $this->verifyParam($request);
        if($result['code'] <= 0){
            return jsonReturn($result['code'],$result['msg']);
        }

        return $next($request);
    }

    public function verifyParam($request){
        $token = $request->header("Authorization");
        $ip=$request->ip();
        $domain=$request->host();
        if(empty($token)){
            return ['code' => 0 , 'msg'=>"token验证失败"];
        }

        // 查询授权数据
        $data=AuthList::where("domain",$domain)->find();
        var_dump($data);
        var_dump($domain);
        return ['code' => 1];

    }

报错信息是think/Request类不存在,由于使用的thinkphp框架,这个错误是不应该的。
检查了一下文件结构发现没有/vendor目录,然后看了一下.gitirnore文件下将/vendor忽略了。

执行

composer install

安装项目依赖,报错:

  Problem 1
    - Root composer.json requires php >=8.0.0 but your php version (7.4.33) does not satisfy that requirement.
  Problem 2
    - topthink/framework[v8.0.0, ..., v8.0.3] require php >=8.0.0 -> your php version (7.4.33) does not satisfy that requirement.
    - Root composer.json requires topthink/framework ^8.0 -> satisfiable by topthink/framework[v8.0.0, v8.0.1, v8.0.2, v8.0.3].

由于PHP版本不正确导致无法安装正确的依赖。

将PHP版本切换为PHP82 重新执行composer install 仍然报错:

PHP Deprecated:  Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///www/server/php/74/bin/composer/vendor/symfony/console/Helper/HelperSet.php on line 112

Deprecated: Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///www/server/php/74/bin/composer/vendor/symfony/console/Helper/HelperSet.php on line 112

这里没太明白是什么意思。在寻找composer目录的过程中看到php.ini文件,想到可能是禁用函数的问题。

默认情况下为了业务的安全php会禁用 putenv 函数,而通过composer安装项目依赖恰好需要这个函数,删除disable_functions中的putenv再次执行composer install

仍然报错:

  [Symfony\Component\Process\Exception\RuntimeException]                                   
  The Process class relies on proc_open, which is not available on your PHP installation.

到这里就很显而易见了,还需要解除对proc_open()函数的禁用。

完成此步骤再次执行安装,成功安装所有依赖。

届ける言葉を今は育ててる
最后更新于 2024-03-20