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

Composer commonly used commands organized

藏色散人
Release: 2019-10-18 14:14:04
forward
3647 people have browsed it

The composer tutorial column below will introduce the commonly used Composer 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
Copy after login

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 https://php.cnpkg.org/

composer config -g repos.packagist composer https://php.cnpkg.org
Copy after login

From Laravel China

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

View all global configurations

composer config -g --list
Copy after login

View individual All project configurations

composer config --list
Copy after login

View a certain configuration

composer config -g repositories.packagist.org
Copy after login

Cancel a certain configuration

composer config -g --unset repos.packagist
Copy after login

Create a new project

Create a Yii project

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

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.
Copy after login

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

apt-get install zip unzip
Copy after login

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
Copy after login

Install new dependent packages

composer require monolog/monolog
Copy after login

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
Copy after login

Remove dependent packages

composer remove monolog/monolog
Copy after login

Initialize a composer.json

composer init
Copy after login

View existing packages

composer info
Copy after login

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

composer install
Copy after login

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

composer update
Copy after login

Clear cache

composer clearcache
Copy after login

Update composer.phar

composer self-update
Copy after login

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!

Related labels:
source:beltxman
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template