composer 使用详解
1,安装
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('SHA384', 'composer-setup.php') === 'aa96f26c2b67226a324c27919f1eb05f21c248b987e6195cad9690d5c1ff713d53020a02ac8c217dbf90a7eacc9d141d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');"mv composer.phar /usr/local/bin/composer
2,配置中国全量镜像
使用如下命令可以看到默认的包地址是{"type":"composer","url":"https?:\/\/packagist.org","allow_ssl_downgrade":true}
composer config -g repo.packagist
使用如下命令设置中国全量镜像
composer config -g repo.packagist composer https://packagist.phpcomposer.com
3,常用命令
composer init #初始化,生成composer.json配置文件 composer search monolog #查找库 composer show --all monolog/monolog #查看库信息,包括版本信息 composer install #根据配置文件安装库 composer require monolog/monolog composer update #更新库