一、安装和使用
1.1 安装
# 全局安装 php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" php composer-setup.php mv composer.phar /usr/local/bin/composer
方式二
curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer
1.2 镜像切换
# 全局切换国内镜像 # 阿里云 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
1.3 基本使用
# 安装依赖包 composer install # 安装依赖 composer require monolog/monolog # 更新所有依赖 composer update # 移除一个包及其依赖 composer remove monolog/monolog # 列出所有已经安装的包 composer show
二、问题及解决
2.1 问题1
执行以下命令:
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
2.2 问题2
but these conflict with your requirements or minimum-stability.
解决:在composer.json中添加以下
"minimum-stability": "dev",
参考
Composer问题集锦
2.3 问题3
[Symfony\Component\Process\Exception\RuntimeException] The Process class relies on proc_open, which is not available on your PHP installation. *
解决方法:
打开php.ini,搜索disable_functions指令
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
找到proc_open并删除即可
同理,一下报错也使用同样的方式处理
proc_get_status() has been disabled for security reasons
# 以下两个配置需要删除 disable_functions = proc_get_status,proc_open
参考
[Symfony\Component\Process\Exception\RuntimeException] The Proc
使用composer提示[ErrorException ]proc_get_status() has been disabled for security reasons 的解决方法
2.4 指定PHP版本
/usr/local/php71/bin/php /usr/local/bin/composer install