search
HomeDevelopment ToolscomposerYou must use these Composer commands!

The following is the tutorial column of composer to introduce you to the common commands of Composer. I hope it will be helpful to friends in need!

You must use these Composer commands!

selfupdate

Update composer itself, please perform composer selfupdate frequently to keep Composer always the latest version .

<span style="font-size: 16px;">composer selfupdate<br/></span>

is equivalent to

<span style="font-size: 16px;">composer self-update<br/></span>

dumpautoload

when we change the composer.json file When autoloading, you need to execute composer dumpautoload to make the autoload take effect immediately. Without having to execute install or update commands.

<span style="font-size: 16px;">composer dumpautoload<br/></span>

is equivalent to

<span style="font-size: 16px;">composer dump-autoload<br/></span>

The dumpautoload command has two commonly used options:

  • --optimize (-o): Convert PSR-0/4 autoloading to classmap for faster loading. This is particularly suitable for production environments, but may take some time to run, so it is not currently the default.
  • --no-dev: Disable autoload-dev rules.

install

<span style="font-size: 16px;">composer install<br/></span>

is defined based on the composer.lock (lock file) or composer.json file in the current directory. Dependencies, install dependent packages.

The install command will first check whether the composer.lock lock file exists. If it exists, it will download the version specified in the composer.lock file, ignoring the definition in the composer.json file.

<span style="font-size: 16px;"># 查看 composer install 的帮助信息<br/>composer install -h<br/><br/># 只安装 require 中定义的依赖,而不安装 require-dev 中定义的依赖<br/>composer install --no-dev<br/></span>

update

If you want to update your dependency version, or you modify the dependency relationship in composer.json, you want composer To perform update operations as defined in the composer.json file, use the update command.

<span style="font-size: 16px;">composer update<br/></span>

require

require command is generally used to install new dependency packages and write dependencies into the composer.json file in the current directory. .

If dependencies are added or changed in the composer.json file, the modified dependencies will be installed or updated.

<span style="font-size: 16px;">composer require<br/></span>

You can also directly specify the dependency packages that need to be installed in the command.

<span style="font-size: 16px;">composer require barryvdh/laravel-ide-helper<br/></span>

Install the specified version of the dependency package.

<span style="font-size: 16px;">composer require barryvdh/laravel-ide-helper:1.0<br/></span>

--dev option corresponds to require-dev. If your dependency package is only used in the development environment, it is recommended to add the --dev option.

<span style="font-size: 16px;">composer require --dev barryvdh/laravel-ide-helper<br/></span>

create-project

You can use create-project to create a new project from an existing package.

It is equivalent to installing the dependencies of this package into its own vendor directory after executing the git clone command.

This command has several common uses:

  • You can quickly deploy your application.
  • You can check out any resource pack and develop patches for it.
  • For multi-person development projects, you can use it to speed up application initialization.
<span style="font-size: 16px;"># 安装 Laravel 项目<br/>composer create-project --prefer-dist laravel/laravel blog 5.5.*<br/></span>

If no version number is specified, the latest version will be installed by default.

--prefer-dist: Install from dist when a package is available.

search

The search command can search for remote dependent packages. Usually it only searches for packages on packagist.org. You can simply enter your search terms.

<span style="font-size: 16px;">composer search monolog<br/></span>

--only-name (-N) option, only searches for the specified name (exact match).

show

#To list installed dependency packages, you can use the show command.

<span style="font-size: 16px;">composer show<br/></span>

List all dependent packages on the mirror site.

<span style="font-size: 16px;">composer show --all<br/></span>

If you want to view detailed information about a specified dependent package, you can enter the package name.

<span style="font-size: 16px;">composer show monolog/monolog<br/></span>

config

config 命令允许你编辑 Composer 的一些基本设置,无论是本地的 composer.json 还是全局的 config.json 文件。

查看 Composer 的全局配置信息:

<span style="font-size: 16px;">composer config -g --list<br/></span>

语法:config [options] [setting-key] [setting-value1] ... [setting-valueN]

setting-key 是配置选项的名称,setting-value1 是配置的值。可以使用数组作为配置的值(像 github-protocols),多个 setting-value 是允许的。

例如,全局配置 Composer 的国内镜像:

<span style="font-size: 16px;"># 推荐使用阿里云 Composer 全量镜像<br/>composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/<br/></span>

选项:

  • --global (-g): 操作 $COMPOSER_HOME/config.json 全局配置文件。如果不指定该参数,此命令将影响当前项目的 composer.json 文件,或 --file 参数所指向的文件。
  • --editor (-e): 使用文本编辑器打开 composer.json 文件。默认情况下始终是打开当前项目的文件。当存在 --global 参数时,将会打开全局的 config.json 文件。
  • --unset; 移除由 setting-key 指定的配置选项。
  • --list (-l): 查看当前配置选项的列表。当存在 --global 参数时,将会显示全局配置选项的列表。
  • --file="..." (-f):在一个指定的文件上操作,而不是 composer.json。它不能与 --global 参数一起使用。

run-script

run-script 命令,可用来手动执行脚本,只需要指定脚本的名称即可。

假如,composer.json 中存在如下脚本。

<span style="font-size: 16px;">{<br/>    "scripts": {<br/>        "post-update-cmd": "MyVendor\\MyClass::postUpdate",<br/>        "post-package-install": [<br/>            "MyVendor\\MyClass::postPackageInstall"<br/>        ],<br/>        "post-install-cmd": [<br/>            "MyVendor\\MyClass::warmCache",<br/>            "phpunit -c app/"<br/>        ]<br/>    }<br/>}<br/></span>

运行所有 post-install-cmd 事件下定义的脚本:

<span style="font-size: 16px;">composer run-script post-install-cmd</span><br/>

更多composer技术文章,请访问composer栏目!                  

The above is the detailed content of You must use these Composer commands!. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:csdn. If there is any infringement, please contact admin@php.cn delete
How to solve the complexity of PHPHTTP request and response processing? The sabre/http library can help you!How to solve the complexity of PHPHTTP request and response processing? The sabre/http library can help you!Apr 17, 2025 pm 09:45 PM

I encountered a tricky problem when developing a project that needs to handle a large number of HTTP requests and responses: PHP's native HTTP handling is too cumbersome and inconsistent, making the code difficult to maintain and scale. After trying multiple methods, I found that the sabre/http library provides a simple and powerful solution that greatly simplifies the processing of HTTP requests and responses, making my project more efficient and maintainable.

How to solve the template problem in TYPO3CMS? Use typo3/cms-fluid!How to solve the template problem in TYPO3CMS? Use typo3/cms-fluid!Apr 17, 2025 pm 09:42 PM

When developing websites using TYPO3CMS, you often encounter problems in template design and management. Especially when complex page layouts and dynamic content need to be created, traditional template engines may not meet the needs. Fortunately, the typo3/cms-fluid extension can help us solve these problems easily.

How to solve the problem of sending PHP emails? Help you with Composer and MailjetAPIHow to solve the problem of sending PHP emails? Help you with Composer and MailjetAPIApr 17, 2025 pm 09:39 PM

I encountered a tricky problem when developing a user feedback system: how to efficiently process and send large amounts of user emails. Traditional mail delivery methods are not only complicated, but also prone to errors. After some exploration, I discovered Mailjet's API and its PHP encapsulation library mailjet/mailjet-apiv3-php. After rapid integration through Composer, I completely solved my problem.

How to solve the locking problem in concurrent execution? Using the mallusch/lock library is OK!How to solve the locking problem in concurrent execution? Using the mallusch/lock library is OK!Apr 17, 2025 pm 09:36 PM

Ensuring mutually exclusive access to critical code segments is critical when handling concurrently executed applications. Recently, I encountered a tricky problem when developing a system that requires multiple users to access bank account balances at the same time: multiple users try to update their account balances at the same time, resulting in inconsistent data. I've tried multiple ways to solve this problem, but it doesn't work well. It wasn't until I discovered the malkusch/lock library that I really solved my troubles.

How to solve PHP email management problem? It can be done easily using the php-imap/php-imap library!How to solve PHP email management problem? It can be done easily using the php-imap/php-imap library!Apr 17, 2025 pm 09:33 PM

I encountered a tough problem when developing a project that needs to process mail: how to efficiently manage mailboxes, get and delete mail. After trying multiple methods, I found that the php-imap/php-imap library not only solves my problem, but also greatly improves the efficiency and stability of the program.

How to solve the expansion problem of TYPO3 background management module? It can be done easily with Composer!How to solve the expansion problem of TYPO3 background management module? It can be done easily with Composer!Apr 17, 2025 pm 09:30 PM

When using TYPO3CMS, you often encounter problems with the extension of the background management module. Especially when you need to add new feature modules or update existing modules, you may encounter various dependency and compatibility issues. By using Composer, we can easily manage and extend TYPO3 backend modules to solve these problems.

How to solve the Composer dependency license issue? Use dominikb/composer-license-checker!How to solve the Composer dependency license issue? Use dominikb/composer-license-checker!Apr 17, 2025 pm 09:27 PM

When managing PHP project dependencies using Composer, you often encounter a difficult problem: How to ensure that all dependent licenses meet project requirements? Inadvertently introduced some licenses that do not meet company policies or project needs, it may lead to legal risks or project compliance issues. Fortunately, the dominikb/composer-license-checker tool can help us solve this problem easily.

How to solve the problem of WebDAV service in PHP? Use sabre/dav to do it!How to solve the problem of WebDAV service in PHP? Use sabre/dav to do it!Apr 17, 2025 pm 09:24 PM

I encountered a tricky problem when developing a project that requires WebDAV functionality: how to efficiently implement WebDAV, CalDAV and CardDAV services in PHP. After trying multiple methods, I found that the sabre/dav library not only solves my problem, but also provides powerful features and flexibility.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.