Composer is the best dependency management tool on PHP, so as a literary phper it has to get up.
Get started = = into the pit?
Many friends do not want to get started with this goods, in fact, I am not too willing to get started with this goods, the most important reason is the wall .
Said more is a tear, and at that time all kinds of mirrors is a pit daddy, no one can use, even if can use, also basically spell character, basically are not stable.
Even then I was manually installed various packages, encountered n many pits, such as reliance also manual download, manual import. Alas. More than ever looking for various types of plug-ins when the eggs ache extremely.
Installing Composer
In fact, it is simple also easy to say trouble, because to divide *nix and win platform, so directly dropped the link to their own bullish.
Installation-*nix
Install-Windows
The test is successful after the installation is complete.
$ composer-v
Output something like that.
Composer version 1.0-dev (1a5445132f1cbd366294924dc2fd0114dd4c843a) 2016-03-14 17:39:12
OK, congratulations, you can take the next step.
What the hell is the mirror?
Do not know the mirror of the celestial programmer, is not a good yard farming.
As a result of strong GFW can not be on some excellent foreign sites, so all kinds of mirror server was born, help us to the resources on these sites into the country, we can download these resources by modifying a configuration. And these resources are synchronized on a regular basis and do not need to worry about resource obsolescence.
That is because of this, n many people deterred, to now do not dare to use Composer, feel good pity, such a good tool.
At present the only stable Composer mirror only packagist/composer China full-volume mirror this one, although occasional convulsions.
The use of the method is also very simple, recommended global configuration image.
Open a command-line window (Windows user) or console (Linux, MAC user) and execute the following command:
$ composer Config-g Repo.packagist composer https://packagist.phpcomposer.com
OK, the mirror problem is done, and then we can start learning Composer.
Using Composer
The official course, though comprehensive, is verbose. For example, his first example is to manually create a Composer.json and then write a dependency, and then install the module package in JSON via the composer installation. Although it can't be said wrong, very few people use it now, because it's too much trouble.
Let's take some regular usage, like I want to install YII2.
The official Yii installation method is to install the Composer Asset plugin first:
$ PHP Composer.phar global require "fxp/composer-asset-plugin:~1.1.1"
Then install the basic Application template:
$ php composer.phar create-project yiisoft/yii2-app-basic Basic 2.0.7
Or install an advanced application Template:
$ php Composer.phar create-project yiisoft/yii2-app-advanced Advanced 2.0.7
But I'm going to have a myriad of these mistakes.
Failed to decode Response:zlib_decode (): Data errorretrying with degraded mode, check HTTPS://GETCOMPOSER.ORG/DOC/ARTICL Es/troubleshooting.md#degraded-mode for more info
Baidu later found adding--prefer-dist parameters can be.
$ php Composer.phar create-project yiisoft/yii2-app-advanced Advanced 2.0.7--prefer-dist
PS: If you get stuck in the installation, probably is a mirror of the convulsions, try a few more times just fine.
OK, normal installation, and then look through the document, found that there are--prefer-source and--prefer-dist parameters, corresponding to download the package two ways: source (source) and Dist (release), we certainly want to install the dist (release) version.
OK, this is the installation, then I want to add new plugins, new dependencies so do?
And listen to tell ... (′ ω ')