Composer installation and configuration

Introduction to Composer

Composer is a dependency management tool for PHP. It allows you to declare the code libraries your project depends on, and it will install them for you in your project.

For users, Composer is very simple. You can download the required code package to the vendor directory with a simple command, and then the developer can import the package and use it. The key lies in the composer.json defined by your project. Define the package that the project needs to depend on (there may be multiple), and the dependent package may depend on other packages (this is the benefit of the component), these do not bother you, Composer will automatically download everything you need, everything lies in composer. The definition of json.

Composer download

Download link: https://getcomposer.org/download/

Composer installation

After downloading the installer, just run it directly:

Then select the location of the PHP program:

Then continue to the next step:

Proceed to the next step:

Start to download and install:

Successful installation:

Run the test under CMD:

Composer configuration

After installing Composer, we need to change the warehouse mirror to domestic, otherwise the download is very slow and slow:

All projects in the global configuration will use the following mirror addresses:

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

When you need to cancel the mirroring address configuration, you can use the following command:

composer config -g --unset repos.packagist

Composer use

The use of Composer is also very simple. For instructions, please refer to: https://docs.phpcomposer.com/03-cli.html

Here are a few commonly used commands:

  • Search package————composer search keyword
  • Installation package-composer require package name
  • Installation package——composer install (just enter the root directory of the package and run it)
  • Update package——composer update
  • Delete package-composer remove package name

When installing a certain CMS, we can install it directly according to the instructions. For example, here is to directly download the installation package and then run composer install:

 

Guess you like

Origin blog.csdn.net/Fly_hps/article/details/106813292