brief introduction
-
Dependent processing is prone to problems -
Very complex configuration -
The hard to use command line interface was born in Composer. Composer is a tool used to manage dependencies in PHP. You can declare the dependent PHP packages in your own project, and Composer will help us install these dependent library files. This is similar to the yum command in CentOs.
Composer function
-
Composer is used to manage (update, download, uninstall) php packages -
Composer can also realize automatic loading
Steps for installing composer in Linux
-
Install ntpdate tool $ yum -y install ntp ntpdate -
Set system time to synchronize with network time $ ntpdate cn.pool.ntp.org -
Write system time to hardware time $ hwclock --systohc
//Composer download address https://getcomposer.org/composer.phar //Move the downloaded composer.phar file to the/usr/local/bin directory to make the command available globally mv composer.phar /usr/local/bin/composer
$ composer config -g repo.packagist composer https://packagist.phpcomposer.com
Use Composer to install dependent packages
Create a composer file in the project directory to indicate the dependency, such as your project dependency on Monolog
{ "require":{ "monolog/monolog":"1.21.*" } }
Installation dependency
-
Installation dependency is very simple, just run it in the project directory: $ composer install
-
If the composer is not installed globally, run $ php composer.phar install
-
Another way to download packages using composer $composer install package name
Code installed using Composer
require 'vendor/autoload.php';
Composer warehouse
Update Composer
$ composer self-update
Update Dependencies
$ composer update
$ composer update vendor/package vendor/package2
How to use the code we wrote
"autoload":{ "psr-4":{ "app\\Controller\\":"app/Controller", "app\\Model\\":"app/Model" } } "app\\Controller\\":"app/Controller", The namespace is on the left ("app Controller ") On the right ("app/Controller") is the code directory of the corresponding namespace
$ composer update
//You can also use your own code require('./ vendor/autoload.php'); <
Complete steps for using composer for the first time
https://getcomposer.org/composer.phar
$ mv composer.phar /usr/local/bin/composer
composer init
{ "require":{ "monolog/monolog":"1.21.*", "phpoffice/phpexcel": "^1.8", "overtrue/wechat": "~3.1" } }
$ composer config -g repo.packagist composer https://packagist.phpcomposer.com
$ composer install
How to install the package after composer.json has been generated
$ composer require predis/predis