Table of Contents
Install
Install Chinese image
Ignore version matching
Create Project-Parameters
Self-update-parameters
Search-Parameters
更新-参数
安装-参数
Home Development Tools composer Some commands\parameters\descriptions in composer

Some commands\parameters\descriptions in composer

Dec 11, 2020 pm 03:50 PM
composer

The following tutorial column of composer will introduce some commonly used commands\parameters\instructions of composer. I hope it will be helpful to friends in need!

Install

curl -sS https://getcomposer.org/installer | php
Copy after login

or

php -r "readfile('https://getcomposer.org/installer');" | php
Copy after login

Global installation

mv composer.phar /usr/local/bin/composer
Copy after login

Install Chinese image

composer config -g repo.packagist composer https://packagist.phpcomposer.com
Copy after login

Ignore version matching

composer install/update --ignore-platform-reqs

Install plug-in package?

composer global require "fxp/composer-asset-plugin:1.2.0“
Copy after login

Create project create-project

You can use Composer to create a new project from an existing package. This is equivalent to executing a git clone or svn checkout command to install the dependencies of this package into its own vendor directory.

This command has several common uses:

  1. You can quickly deploy your application.
  2. You can check out any resource pack and develop patches for it.
  3. For multi-person development projects, you can use it to speed up application initialization.

To create a new Composer-based project, you can use the "create-project" command. Pass a package name and it will create the project's directory for you. You can also specify a version number in the third parameter, otherwise the latest version will be retrieved.

If the directory does not currently exist, it will be automatically created during the installation process.

php composer.phar create-project doctrine/orm path 2.2.*
Copy after login

In addition, you can also start this project through the existing composer.json file without using this command.

By default, this command will look for the package you specify on packagist.org.

Create Project-Parameters

  • --repository-url: Provide a custom repository to search for packages, this will be used instead of packagist.org. It can be an HTTP URL pointing to a composer resource library, or a local path pointing to a packages.json file.
  • --stability (-s): The lowest stable version of the resource package, the default is stable.
  • --prefer-source: When a package is available, install it from source.
  • --prefer-dist: When a package is available, install it from dist.
  • --dev: Install the packages listed in the require-dev field.
  • --no-install: Disable installation package dependencies.
  • --no-plugins: Disable plugins.
  • --no-scripts: Disable the execution of scripts defined in the root resource package.
  • --no-progress: Remove progress information, which can avoid confusing display in some terminals or scripts that do not handle line breaks.
  • --keep-vcs: Skip missing VCS when creating. This is useful if you are running the create command in non-interactive mode.

Self-update self-update

To upgrade Composer itself to the latest version, just run the self-update command. It will replace your composer.phar file to the latest version.

php composer.phar self-update
Copy after login

If you want to upgrade to a specific version, you can simply specify it like this:

php composer.phar self-update 1.0.0-alpha7
Copy after login

If you have installed Composer for the entire system (see Global Installation), you may need to Run it under root permissions:

sudo composer self-update
Copy after login

Self-update-parameters

  • --rollback (-r): Roll back to the last version you have installed .
  • --clean-backups: Delete old backups during the update process, making the current version after the update the only available backup.

Search search

The search command allows you to search for dependency packages for the current project. Usually it only searches packages on packagist.org , you can simply enter your search criteria.

php composer.phar search monolog
Copy after login

You can also perform a multi-criteria search by passing multiple parameters.

Search-Parameters

  • --only-name (-N): Search only for the specified name (exact match).

Declare dependencies require

##require The command adds a new dependency package to the current directory composer.json in the file.

php composer.phar require
Copy after login
When adding or changing dependencies, the modified dependencies will be installed or updated.

If you do not want to specify dependent packages interactively, you can specify dependent packages directly in this command.

php composer.phar require vendor/package:2.* vendor/package2:dev-master
Copy after login
Declare dependencies-parameters

    --prefer-source: When there is an available package, install it from
  • source.
  • --prefer-dist: When a package is available, install it from
  • dist.
  • --dev: Install the packages listed in the
  • require-dev field.
  • --no-update: Disable automatic updates of dependencies.
  • --no-progress: Remove progress information, which can avoid confusing display in some terminals or scripts that do not handle line breaks.
  • --update-with-dependencies Update the dependencies of the newly installed package together.
Update

update

To get the latest versions of dependencies and upgrade the

composer.lock file, you should use update Order.

php composer.phar update
Copy after login

这将解决项目的所有依赖,并将确切的版本号写入 composer.lock

如果你只是想更新几个包,你可以像这样分别列出它们:

php composer.phar update vendor/package vendor/package2
Copy after login

你还可以使用通配符进行批量更新:

php composer.phar update vendor/*
Copy after login

更新-参数

  • --prefer-source: 当有可用的包时,从 source 安装。
  • --prefer-dist: 当有可用的包时,从 dist 安装。
  • --dry-run: 模拟命令,并没有做实际的操作。
  • --dev: 安装 require-dev 字段中列出的包(这是一个默认值)。
  • --no-dev: 跳过 require-dev 字段中列出的包。
  • --no-scripts: 跳过 composer.json 文件中定义的脚本。
  • --no-plugins: 关闭 plugins。
  • --no-progress: 移除进度信息,这可以避免一些不处理换行的终端或脚本出现混乱的显示。
  • --optimize-autoloader (-o): 转换 PSR-0/4 autoloading 到 classmap 可以获得更快的加载支持。特别是在生产环境下建议这么做,但由于运行需要一些时间,因此并没有作为默认值。
  • --lock: 仅更新 lock 文件的 hash,取消有关 lock 文件过时的警告。
  • --with-dependencies 同时更新白名单内包的依赖关系,这将进行递归更新。

安装 install

install 命令从当前目录读取 composer.json 文件,处理了依赖关系,并把其安装到 vendor 目录下。

php composer.phar install
Copy after login

如果当前目录下存在 composer.lock 文件,它会从此文件读取依赖版本,而不是根据 composer.json 文件去获取依赖。这确保了该库的每个使用者都能得到相同的依赖版本。

如果没有 composer.lock 文件,composer 将在处理完依赖关系后创建它。

安装-参数

  • --prefer-source: 下载包的方式有两种: source 和 dist。对于稳定版本 composer 将默认使用 dist 方式。而 source 表示版本控制源 。如果 --prefer-source 是被启用的,composer 将从 source 安装(如果有的话)。如果想要使用一个 bugfix 到你的项目,这是非常有用的。并且可以直接从本地的版本库直接获取依赖关系。
  • --prefer-dist: 与 --prefer-source 相反,composer 将尽可能的从 dist 获取,这将大幅度的加快在 build servers 上的安装。这也是一个回避 git 问题的途径,如果你不清楚如何正确的设置。
  • --dry-run: 如果你只是想演示而并非实际安装一个包,你可以运行 --dry-run 命令,它将模拟安装并显示将会发生什么。
  • --dev: 安装 require-dev 字段中列出的包(这是一个默认值)。
  • --no-dev: 跳过 require-dev 字段中列出的包。
  • --no-scripts: 跳过 composer.json 文件中定义的脚本。
  • --no-plugins: 关闭 plugins。
  • --no-progress: 移除进度信息,这可以避免一些不处理换行的终端或脚本出现混乱的显示。
  • --optimize-autoloader (-o): 转换 PSR-0/4 autoloading 到 classmap 可以获得更快的加载支持。特别是在生产环境下建议这么做,但由于运行需要一些时间,因此并没有作为默认值。

The above is the detailed content of Some commands\parameters\descriptions in composer. For more information, please follow other related articles on the PHP Chinese website!

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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

Use Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundle Use Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundle Apr 18, 2025 am 11:48 AM

When developing an e-commerce website, I encountered a difficult problem: how to provide users with personalized product recommendations. Initially, I tried some simple recommendation algorithms, but the results were not ideal, and user satisfaction was also affected. In order to improve the accuracy and efficiency of the recommendation system, I decided to adopt a more professional solution. Finally, I installed andres-montanez/recommendations-bundle through Composer, which not only solved my problem, but also greatly improved the performance of the recommendation system. You can learn composer through the following address:

Solve caching issues in Craft CMS: Using wiejeben/craft-laravel-mix plug-in Solve caching issues in Craft CMS: Using wiejeben/craft-laravel-mix plug-in Apr 18, 2025 am 09:24 AM

When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

How to simplify email marketing with Composer: DUWA.io's application practices How to simplify email marketing with Composer: DUWA.io's application practices Apr 18, 2025 am 11:27 AM

I'm having a tricky problem when doing a mail marketing campaign: how to efficiently create and send mail in HTML format. The traditional approach is to write code manually and send emails using an SMTP server, but this is not only time consuming, but also error-prone. After trying multiple solutions, I discovered DUWA.io, a simple and easy-to-use RESTAPI that helps me create and send HTML mail quickly. To further simplify the development process, I decided to use Composer to install and manage DUWA.io's PHP library - captaindoe/duwa.

Using Dicr/Yii2-Google to integrate Google API in YII2 Using Dicr/Yii2-Google to integrate Google API in YII2 Apr 18, 2025 am 11:54 AM

VprocesserazrabotkiveB-enclosed, Мнепришлостольностьсясзадачейтерациигооглапидляпапакробоглесхетсigootrive. LEAVALLYSUMBALLANCEFRIABLANCEFAUMDOPTOMATIFICATION, ČtookazaLovnetakProsto, Kakaožidal.Posenesko

How to view the version number of laravel? How to view the version number of laravel How to view the version number of laravel? How to view the version number of laravel Apr 18, 2025 pm 01:00 PM

The Laravel framework has built-in methods to easily view its version number to meet the different needs of developers. This article will explore these methods, including using the Composer command line tool, accessing .env files, or obtaining version information through PHP code. These methods are essential for maintaining and managing versioning of Laravel applications.

How to use Composer to improve the security of Laravel applications: Applications of wiebenieuwenhuis/laravel-2fa library How to use Composer to improve the security of Laravel applications: Applications of wiebenieuwenhuis/laravel-2fa library Apr 18, 2025 am 11:36 AM

When developing a Laravel application, I encountered a common but difficult problem: how to improve the security of user accounts. With the increasing complexity of cyber attacks, a single password protection is no longer enough to ensure the security of users' data. I tried several methods, but the results were not satisfactory. Finally, I installed the wiebenieuwenhuis/laravel-2fa library through Composer and successfully added two-factor authentication (2FA) to my application, greatly improving security.

See all articles