天天看点

composer的基本使用和常见报错解决一、安装和使用二、问题及解决

composer

一篇不错的文章

Composer 安装与使用

# 全局安装
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"

php composer-setup.php

mv composer.phar /usr/local/bin/composer
      

# 全局切换国内镜像
# 阿里云
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
# 中国全量镜像
composer config -g repo.packagist composer https://packagist.phpcomposer.com

# 取消全局配置
composer config -g --unset repos.packagist


# 当前工程切换配置
composer config repo.packagist composer https://mirrors.aliyun.com/composer/

# 取消当前工程配置
composer config --unset repos.packagist

# 清除缓存
composer clear      

# 安装依赖包
composer install

# 安装依赖
composer require monolog/monolog

# 更新所有依赖
composer update

# 移除一个包及其依赖
composer remove monolog/monolog

# 列出所有已经安装的包
composer show      

执行以下命令:

composer require sonata-project/doctrine-orm-admin-bundle "2.3.*"      

报错:

PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 32 bytes)      

解决:

php -r "echo ini_get('memory_limit').PHP_EOL;"  # 查看memory大小

COMPOSER_MEMORY_LIMIT=-1 composer require sonata-project/doctrine-orm-admin-bundle  # 临时设置memory大小
      

参看官方说明(打开太慢了):

https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors

but these conflict with your requirements or minimum-stability.      

解决:在composer.json中添加以下

"minimum-stability": "dev",      

参考

Composer问题集锦