You can declare external libraries in your own projects, and Composer will install those libraries for you.

Composer can also manage projects. Overall, Composer is a PHP-based version control, project management tool.

English website: https://getcomposer.org/ English mirror: Chinese website: https://packagist.org https://www.phpcomposer.com/ Chinese image: https://pkg.phpcomposer.com/

Install the Composer


There are only two things you need to do to install Composer

1. Download and install Composer. phar 2. Configure Chinese image

Details are as follows:


1. Install globally and download the latest version of composer. Phar from the official website

Make sure PHP is available and that version B is greater than 5.6

php -v

The version and date of the composer should be the same as the website

php composer.phar -v

3. Finally, set it to a global command

mv composer.phar /usr/local/bin/composer

The installation is complete at this point

4. Next, configure the Chinese image

Global replacement:

composer config -g repo.packagist composer https://packagist.phpcomposer.com

Local configuration :(for current directory only)

composer config repo.packagist composer https://packagist.phpcomposer.com

The above command will automatically add the configuration information of the image to the end of the composer.json file in the current project (you can add it yourself manually) :

"repositories": {
     "packagist": {
         "type": "composer",
         "url": "https://packagist.phpcomposer.com"
     }
 }

To take the MongoDB extension as an example, add the composer.json file to the current directory with the following contents

{"require": {"monolog/monolog": "1.2.*"}}

After executing the above command, becomes

{" require ": {" monolog/monolog" : "1.2. *}", "repositories" : {" packaglist ": {" type" : "composer", "url" : "https://packagist.phpcomposer.com" } }}

Then perform composer install to install MongoDB

Composer installation TP5


To install directly, you don’t need to create composer.json; simply execute the following command (pos).

composer create-project topthink/think tp5 --prefer-dist