Home>Article>Development Tools> Composer commonly used commands organized

Composer commonly used commands organized

藏色散人
藏色散人 forward
2019-10-18 14:14:04 3487browse

The composer tutorial column below will introduce the commonly usedComposer commands. I hope it will be helpful to friends in need!

Composer commonly used commands organized

composer is a PHP package management tool. It can be used to easily build projects, load third-party packages, and various complex dependencies, automatic loading and other needs.

Install composer

curl -sS https://getcomposer.org/installer | php -- \ --install-dir=/usr/bin \ --filename=composer

After installation, use composer -v to view the version number and other information.

Modify the code warehouse source

Since the default source server of composer is abroad, due to well-known reasons, the download speed is slow, we need to replace it with the full domestic source. Currently, these are available Two:

From //m.sbmmt.compkg.org/

composer config -g repos.packagist composer //m.sbmmt.compkg.org

From Laravel China

composer config -g repo.packagist composer https://packagist.laravel-china.org

View all global configurations

composer config -g --list

View individual All project configurations

composer config --list

View a certain configuration

composer config -g repositories.packagist.org

Cancel a certain configuration

composer config -g --unset repos.packagist

Create a new project

Create a Yii project

composer create-project --prefer-dist yiisoft/yii2-app-basic basic.com

You can also use --prefer-source for --prefer-dist after the create-project command. The difference between them is:

--prefer-dist will download the .zip compressed package from github and Cache locally. The next time you install it, it will be loaded locally, greatly speeding up the installation. But she did not keep the .git folder and no version information. Suitable for development based on this package.

--prefer-source will clone the source code from github and will not cache it locally (the latest version can also use cache). The .git folder is preserved, allowing version control. Suitable for modifying source code.

It is recommended to use --prefer-dist to speed up the speed. When using it, there may be warnings similar to the following:

Failed to download yiisoft/yii2-gii from dist: The zip extension and unzip command are both missing, skipping. Your command-line PHP is using multiple ini files. Run `php --ini` to show them.

The zip and unzip toolkits are missing in the environment, install them:

apt-get install zip unzip

The yiisoft/yii2-app-basic that follows is the project package name, and the basic.com at the end specifies the new project folder.

Retrieve packages in the warehouse

composer search monolog/monolog

Install new dependent packages

composer require monolog/monolog

Control version number

# 指定版本 composer require monolog/monolog 1.24.0 # 版本范围 # 有效的运算符有 >、>=、<、<=、!=,运算符中间使用逗号隔开视作逻辑AND,使用|隔开,视作逻辑OR,AND的优先级更高 # 支持通配符 * # 支付波浪号运算符 ~ 限定在最低版本和下一个重要版本更新之前 # 以下都是有效的版本号 # 版本大于等于1.0 >=1.0 # 版本大于等于1.0并且小于2.0 >=1.0,<2.0 # 版本大于等于1.0并且小于1.1,或者版本大于等于1.2 >=1.0,<1.1|>=1.2 # 相当于>=1.0,<1.1 1.0.* # 相当于>=1.2,<2.0 ~1.2 # 相当于>=1.2.3,<1.3 ~1.2.3 # 相当于>=1.2.3,<2.0.0 在多于2位的版本号的时候跟 ~ 有区别 ^1.2.3

Remove dependent packages

composer remove monolog/monolog

Initialize a composer.json

composer init

View existing packages

composer info

Install dependent packages according to composer.lock (if they exist), otherwise according to composer.json

composer install

According to composer .json updates dependencies to the latest version within the specified range, and updates composer.lock file

composer update

Clear cache

composer clearcache

Update composer.phar

composer self-update

The above is the detailed content of Composer commonly used commands organized. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:beltxman. If there is any infringement, please contact admin@php.cn delete