1 安装前准备
先安装php
再安装php-json扩展
yum install php-json
参考 https://blog.csdn.net/alinathz/article/details/105885254
2 安装
官网安装方法 https://getcomposer.org/download/
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');"
进行composer.phar下载的目录,运行
php composer.phar
3 全局命令配置
只需要将composer.phar文件拷贝到全部的bin目录即可
mv composer.phar /usr/local/bin/composer
检测是否移动成功
composer -v
4 将国外镜像改为国内
4.1 查看全局所有的配置
composer config -l -g
4.2 查看当前全局镜像
composer config -l -g|grep repositories.packagist.org.url
4.3 设置成国内镜像
4.3.1 阿里云
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
4.3.2 中国镜像地址
composer config -g repo.packagist composer https://packagist.phpcomposer.com
4.3.3 还原成默认地址
composer config repo.packagist composer https://packagist.org -g composer config -g --unset repos.packagist
4.3.4 清除所有 package 缓存
composer clear-cache
4.3.5 单个项目配置
只想单独配置某个项目,进入到该目录的文件夹下 并把上面的-g去掉
当composer.json中有两个数据源,先访问第一个,找不到再访问第二个,依次进行,packagist最后一个执行,优先执行其他。
repositories": { "packagist": { "type": "composer", "url": "https://mirrors.aliyun.com/composer/" }, "1": { "type": "composer", "url": "https://asset-packagist.org" } }
5 composer更新版本
composer self-update
6 卸载
6.1 卸载各种依赖包:
composer remove phpoffice/phpexcel
6.2 删除composer:
where composer
然后删除文件即可
使用
官网使用书册 https://docs.phpcomposer.com/03-cli.html
https://blog.csdn.net/u012946588/article/details/78996236