Home>Article>Development Tools> Do you also want to learn composer? -Introduction

Do you also want to learn composer? -Introduction

藏色散人
藏色散人 forward
2021-04-30 10:00:45 2143browse

The following is an introduction to composer from thecomposertutorial column. I hope it will be helpful to friends in need!

Do you also want to learn composer? -Introduction

Composer is a dependency management tool and is used quite frequently. High. Especially for a lazy programmer like me, I will never reinvent the wheel when there is a ready-made wheel. It is similar to the package management tools of other programming languages, such as maven for java and npm for js. It is also very different in use.

It mainly consists of three parts: command line tool, package warehouse, and code library. The package warehouse is what we often call the composer source. You can also publish your own packages on it. I will introduce the publishing process in detail in the subsequent actual combat; code libraries such as the more common github, gitlab, etc.; command line tools such as Windows cmd, Mac terminal, etc.;

Next I will use a few articles to briefly talk to you about composer.

Installation method

There are two main ways to install composer, one is global installation and the other is local installation. The specific installation method can be found on Baidu or Google (if during the installation process If there is a problem, you can leave a message).

After global installation, you can use the command line tool to run the composer command at any location:

> composer -V

After local installation, you need to place the composer.phar packaging file in the project where you need to run composer in the root directory.

> php composer.phar -V

Mirror switching

Composer's default mirror source is often slow to download due to some reasons. In order to improve our development efficiency, we need to perform a mirror switching operation. It is recommended to switch globally (example Alibaba Cloud image is used):

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

You can use the following command to check whether the setting is successful:

> composer config -g -l

Simple use

The most common usage scenario of composer is to install dependency packages.

For example, the logging function is often needed in daily development. At this time, it may be troublesome and time-consuming to conceive, design, and implement a logging function by ourselves, so we will find others to develop it on github or some open source communities. Use the package directly, such as monolog/monolog.

Of course there are others, such as WeChat development SDKovertrue/wechat, payment-related yansongda/pay, etc. The specific installation method is as follows:

> composer require monolog/monolog

Another common usage scenario is initialization an item.

Friends who use laravel should know that when we initialize a laravel project, we often use the following command:

> composer create-project --prefer-dist laravel/laravel blog

Summary

This article briefly introduces the installation and installation of composer Use, the commands that appear in this article will be introduced in detail in subsequent articles. If you have any questions, please leave a message.

The above is the detailed content of Do you also want to learn composer? -Introduction. For more information, please follow other related articles on the PHP Chinese website!

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