Composer

Summary: Author: 张亚飞 | 阅读时间: 2 minute read | Published: 2016-03-12
Filed under Categories: LinuxTags: Note,

Composer

Ubuntu 安装 Composer

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Packagist/Composer 中国全量镜像

composer config -g repositories.packagist composer http://packagist.phpcomposer.com

仅修改当前工程配置,仅当前工程可使用该镜像地址:

composer config repo.packagist composer https://mirrors.aliyun.com/composer/

取消配置:

composer config --unset repos.packagist

调试

composer 命令增加 -vvv 可输出详细的信息,命令如下:

composer -vvv require alibabacloud/sdk

清除缓存

sudo composer clearcache  # 清除缓存
sudo rm -r ~/.composer/cache # 清除缓存

不编辑 composer.json 的情况下安装库

composer require "foo/bar:1.0.0"  

强制从 github 克隆源代码

composer update symfony/yaml --prefer-source

安装 Github phpMyAdmin 执行安装命令

cd phpMyAdmin
sudo composer install

出现如下错误

* [Composer\Downloader\TransportException] Your configuration does not allow connection to http://packagist.com. See https://getcomposer.org/doc/06-config.md#secure-http for details
cd ~/.composer/config.json

"config": {
"secure-http": false
}

常见问题

  • composer install 内存限制
$ composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 32 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 32 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.[www@anhuitest bank_api.tenglv.com]$ COMPOSER_MEMORY_LIMIT=-1 composer require sonata-project/doctrineeorm-admin-bundl

查看限制

$ php -r "echo ini_get('memory_limit').PHP_EOL;"
256M

取消限制

COMPOSER_MEMORY_LIMIT=-1 composer install
  • composer update 内存不足
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Removing tymon/jwt-auth (0.5.12)
The following exception is caused by a lack of memory or swap, or not having swap configured
Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details

PHP Warning:  proc_open(): fork failed - Cannot allocate memory in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php on line 957

Warning: proc_open(): fork failed - Cannot allocate memory in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php on line 957

  [ErrorException]
  proc_open(): fork failed - Cannot allocate memory

update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [<packages>]...
  • 动态分配新增交换分区
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1
  • 可以尝试以下方法
php -dmemory_limit=2G /usr/local/bin/composer update
swapoff -a && swapon -a

Comments

Cor-Ethan, the beverage → www.iirii.com