This article mainly shares with you how to install and use composer, mainly in the form of pictures and texts, hoping to help everyone. For more technical articles on composer usage, please visit the composer usage tutorial column to learn!
. Preparation:
1. Download the installation package, https://getcomposer.org/download/ (Recommended video: How to install composer under Windows system)
2. Open extension=php_openssl.dll
3 in the php.ini document .Download php_ssh2.dll, php_ssh2.pdb, http://windows.php.net/downloads/pecl/releases/ssh2/0.12/
4. Put the php_ssh2.dll, php_ssh2.pdb files into php ext folder
5. Restart apache, php
2. Installation:
1. Click next
2. Select the path to the folder where your php.exe is located
3. Click directly next
4. Click install
5. Click finish
6. Open cmd and enter composer directly: The following means the installation is successful
3. Use:
For example, my project is in C:\Users\Administrator\Desktop\phpstudy\phpcode\20 Next, to put it bluntly, it is under the folder `20`.
I now want to use composer to manage components in this folder. What should I do?
1. In the `20` folder Create a composer.json file in the folder. This file contains information about all your components. The content of the file is as follows:
I added the three components I want to use,
{ "require": { "guzzlehttp/guzzle": "4.2.*",//前面是组件名,后面是组件版本 "league/csv": "6.0.*", //php组件很多,组件名和版本都可以从https://packagist.org/获得 "spatie/string": "1.8.*" } }
2 .In the cmd command line, enter the directory `20`,
3. Execute composer install command on the cmd command line, it will automatically download the composer.json file in the `20` folder Those 3 components.
The results are as follows:
As you can see, they A vendor folder is automatically generated, and all components are downloaded under the vendor.
4. Use of components:
1. First of all The autoload.php file under the vendor must be introduced into the file. This is the official automatic loading file.
2.new object, just call the method.
For example:
require 'vendor/autoload.php'; //引入自动加载文件$client=new \GuzzleHttp\Client(); //创建GuzzleHttp组件的对象
$httpResponse=$client->options(); //调用方法
5. It will be very slow when downloading components, which requires modifying the composer configuration file:
1. Enter composer config - in cmd l -g command, get the path of the composer configuration file.
##[home in the picture ] is followed by the path,
2. Open the config.json file under the path. Change the content to:
{ "config": { }, "repositories": [ {"type": "composer", "url": "http://pkg.phpcomposer.com/repo/packagist/"}, {"packagist": false} ] }
About Composer usage record sharing
Composer automatic loading instance analysis
Composer’s detailed introduction
The above is the detailed content of How to install and use composer. For more information, please follow other related articles on the PHP Chinese website!