php扩展管理工具composer的坑、常见问题和解决方法 |
您所在的位置:网站首页 › composer的音标 › php扩展管理工具composer的坑、常见问题和解决方法 |
composer是个好东西,正如他的中文意思,”作曲家“,但一些坑点不知道的话,就不美好了。 如果还有不知道compoesr的同学,请面壁思过5分钟。然后可以搜索到底干啥的。 我自己的理解和10年前或者15年前比。目的就是去除过多的include或者require. 必备背景知识:composer、laravel、shell 简单说明Composer是 PHP 用来管理依赖(dependency)关系的工具。你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer 会帮你安装这些依赖的库文件。 基本操作网上的教程一搜一大把 composer install 安装依赖包 composer update 更新依赖包 composer remove 卸载依赖包 全局参数来一波全局参数 下列参数可与每一个命令结合使用: --verbose (-v): 增加反馈信息的详细度。-v 表示正常输出。-vv 表示更详细的输出。-vvv 则是为了 debug。--help (-h): 显示帮助信息。--quiet (-q): 禁止输出任何信息。--no-interaction (-n): 不要询问任何交互问题。--working-dir (-d): 如果指定的话,使用给定的目录作为工作目录。--profile: 显示时间和内存使用信息。--ansi: 强制 ANSI 输出。--no-ansi: 关闭 ANSI 输出。--version (-V): 显示当前应用程序的版本信息。 需要注意的问题【坑点列表】我以下载laravel为例 1、==== 卡着不动==== 你以为它死了,其实它没死,坑你没商量。 因为某些特殊情况,老外的源特别慢,我们就得把源改为国内的。阿里某个云。 [root@zjt-ecs-1 composertest1]# composer install Do not run Composer as root/super user! See https://getcomposer.org/root for details Loading composer repositories with package information 上面提示,别用root运行,我就用root运行咋了。哈哈 Warning from https://repo.packagist.org: You are using an outdated version of Composer. Composer 2.0 is about to be released and the older 1.x releases will self-update directly to it once it is released. To avoid surprises update now to the latest 1.x version which will prompt you before self-updating to 2.x. Updating dependencies (including require-dev)果断设置 composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/你以为这样就飞速了。但程序运行到什么状态了并不知道。第二个必须设置的。 2、==== 添加-vvv选项 ==== 这样就知道compose这个家伙到底啥情况了。
3、==== 内存不够 ==== Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52Allowed memory size of xxxx 因为在php.ini设置了内存限制,但这个家伙需要更多的内存,才能把扩展列表加载到内存中。 可通过以下命令查看内存设置 # php -r "echo ini_get('memory_limit').PHP_EOL;"其实看不看也没啥用,看了也还是不行,得改下。哈哈。 两个解决方法: 1)临时设置php.ini 里面的memory_limit 为更大的值。更新完再设置为原样。 找不到php.ini的同学 在命令行里面 #php -i | grep 'php.ini'2)直接命令行通过参数修改 [root@zjt-ecs-1 composertest1]# php -d memory_limit=-1 composer install -vvv Could not open input file: composer你以为行了,其实还不行,composer需要绝对路径 [root@zjt-ecs-1 composertest1]# whereis composer composer: /usr/bin/composer.phar /usr/bin/composer /usr/local/bin/composer这样就可以运行了。 [root@zjt-ecs-1 composertest1]# php -d memory_limit=-1 /usr/bin/composer install -vvv
一个怎么把dev的包也搞到服务器上了。接着设置。
3、==== 不安装多余的dev包 ==== # php -d memory_limit=-1 /usr/bin/composer --no-dev install -vvv4、==== 不更新多余的dev包 ==== Updating dependencies (including require-dev) 说明开始更新dev依赖了。 [root@zjt-ecs-1 composertest1]# composer update Do not run Composer as root/super user! See https://getcomposer.org/root for details Loading composer repositories with package information Warning from https://mirrors.aliyun.com/composer: You are using an outdated version of Composer. Composer 2.0 is about to be released and the older 1.x releases will self-update directly to it once it is released. To avoid surprises update now to the latest 1.x version which will prompt you before self-updating to 2.x. Updating dependencies (including require-dev) ^C5、 ==== dev 依赖的包,不安装也对php版本有要求 ==== 情况是这样的。composer示例 "mockery/mockery
虽然用 --no-dev参数可以不安装 require-dev的包,但安装还是会检查版本的。 我服务器的php PHP 7.2.26 走你。 composer install --no-dev --prefer-dist -vvv就会得到下面的错误 Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for mockery/mockery 1.4.1 -> satisfiable by mockery/mockery[1.4.1]. - mockery/mockery 1.4.1 requires php ^7.3 || ^8.0 -> your PHP version (7.2.26) does not satisfy that requirement. Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.晕死,不是--no-dev不是不安装dev的包吗? 结果网上搜索显示,这个家伙有bug.
我在php 7.3的环境下运行,同样的代码 #composer install --no-dev --prefer-dist -vvv可以正常运行,而且也不会安装dev依赖的包
服务器要不删除,要不降低版本,即使不安装这个包
真是坑你没商量。 基本上就是哪里不行改哪里 1、设置源 # composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ 2、-vvv选项 # composer install -vvv 3、设置内存 # php -d memory_limit=-1 4、不安装dev包 # /usr/bin/composer --no-dev install |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |