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

Do you also want to learn composer? -Introduction

藏色散人
Release: 2021-04-30 18:53:54
forward
2335 people have browsed it

The following is an introduction to composer from the composer tutorial 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
Copy after login

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

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

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

> composer config -g -l
Copy after login

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

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

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!

Related labels:
source:segmentfault.com
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