如何添加和使用composer
安装:
1. 下载Composer安装脚本:
curl -sS https://getcomposer.org/installer | php
2. 重命名以及移动到/usr/local/bin/composer:
sudo mv composer.phar /usr/local/bin/composer
3. 给予执行权限:
sudo chmod +x /usr/local/bin/composer
4. 加入环境变量:
PATH=/usr/local/bin:$PATH
使用composer:
1. 安装组件:
composer require vendor/package
vendor/package需要被替换成组件的厂商和包名。
如何找到好的组件:
可以上https://github.com/ziadoz/awesome-php来查看,这个库由专人维护。
然后可以到https://packagist.org里去搜索,然后让composer进行安装。
composer.json里require和require-dev的区别:
APP会在不同的环境运行,所有的依赖都会写到composer.json里面。require section是用来记录production和staging的依赖关系,而require-dev是用来记录developing以及testing环境的依赖关系。
composer install 会同时安装production和development的依赖
composer install –no-dev 只会安装production里的依赖
Updating your dependencies:
Composer creates a file called composer.lock which stores the exact version of each package it downloaded when you first ran composer install. If you share your project with others, ensure the composer.lock file is included, so that when they run composer install they\’ll get the same versions as you. To update your dependencies, run composer update. Don\’t use composer update when deploying, only composer install, otherwise you may end up with different package versions on production.