Composer basic concepts, installation, and use

What is the Composer

Composer is PHP dependency management tool. It allows you to declare the project relies code base, it will install them for you in your project. It is similar in Ruby Gem, and node.js in NPM.

Why Composer

Use existing PHP code method / library. Previous methods: copy / paste, include, require.

Composer: management project dependencies, automatic loading and so on.

Installation Composer

Linux, MacOS

php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
sudo mv -i composer.phar /usr/local/bin/composer

Windows

Download and run the Composer-Setup.exe, it will install the latest version of Composer, and set system environment variables, so you can directly use the composer command in any directory.

Modify the source for domestic mirror

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

The basic use Composer

the init Composer
Composer The require [Package Penalty for name] installation package
Composer install
Composer Update [Package Penalty for name] update package
Composer the Remove [Package Penalty for name]
Composer config the -gl view the global configuration
composer show lists the current project to package information

Automatically load

Only need to add the following line to guide your project file:

require 'vendor/autoload.php';
He published 188 original articles · won praise 88 · views 580 000 +

Guess you like

Origin blog.csdn.net/henryhu712/article/details/103608062