laravel 通过 composer install 安装第三方库,宝塔需要得配置项
首先是 composer 版本,正常情况下应该是 composer self-update [--stable]
,但当我更新到最新的 2.3.7,再去 安装确提示:
Composer 2.3.0 dropped support for PHP <7.2.5 and you are running 7.1.33, please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.
所以需要环境中的 PHP 版本要大于 PHP 7.2.5 才能使用 composer 2.3.7 的版本。想要执行 composer self-update --2.2
退回到 composer 2.2,但还是提示这个错误。也就是说当前 composer 需要配合 PHP 7.2.5 以上版本才能工作。
所以先启用一个 PHP 8.0,如果环境中 PHP 依然是 PHP 7.1,可以先将 PHP 7.1 卸载掉。然后执行 composer self-update --2.2
回退 composer 版本为 2.2,最后再切换 PHP 版本为 7.1。
最初始先使用的 PHP 8.0,配合着 composer 2.3.0 安装第三方库的,此时报错:
[root@VM-16-14-centos cstation]# composer install
Do not run Composer as root/super user! See https://getcomposer.org/root for det ails
Continue as root/super user [yes]? yes
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Your lock file does not contain a compatible set of packages. Please run compose r update.
Problem 1
- doctrine/annotations is locked to version v1.4.0 and an update of this pac kage was not requested.
- doctrine/annotations v1.4.0 requires php ^5.6 || ^7.0 -> your php version (8.0.14) does not satisfy that requirement.
Problem 2
- doctrine/cache is locked to version v1.6.2 and an update of this package w as not requested.
- doctrine/cache v1.6.2 requires php ~5.5|~7.0 -> your php version (8.0.14) does not satisfy that requirement.
...
此时 composer 已是最高版本,所以问题不在 composer 上,而是项目的依赖库的 PHP 版本与当前环境中的 PHP 版本不匹配,需要降低 PHP 到合适版本。
在解决了 composer 与 PHP 的版本问题之后,再次 composer install
,报错:
PHP Warning: putenv() has been disabled for security reasons in phar:///www/server/php/80/bin/composer/vendor/composer/xdebug-handler/src/Process.php on line 101
Warning: putenv() has been disabled for security reasons in phar:///www/server/php/80/bin/composer/vendor/composer/xdebug-handler/src/Process.php on line 101
PHP Warning: putenv() has been disabled for security reasons in phar:///www/server/php/80/bin/composer/src/Composer/Util/Platform.php on line 57
Warning: putenv() has been disabled for security reasons in phar:///www/server/php/80/bin/composer/src/Composer/Util/Platform.php on line 57
[ErrorException]
putenv() has been disabled for security reasons
这是宝塔面板的 PHP 版本默认禁用函数 putenv 导致的,禁用函数里还有一个 proc_open 也需要删除掉,不然也会报错。
之后还有必要的扩展:
Your lock file does not contain a compatible set of packages. Please run composer update.
Problem 1
- intervention/image is locked to version 2.6.1 and an update of this package was not requested.
- intervention/image 2.6.1 requires ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension.
这是需要安装 fileinfo,一般还会根据需要安装 opcache 和 redis 扩展。
自此,laravel 安装三方依赖库才算完成。
当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »