参考官方教程:https://docs.phpcomposer.com/00-intro.html
composer require "curl/curl"
{ "name": "test/test", "description": "", "license": "MIT", "authors": [ { "name": "a", "email": "a@gmail.com" } ], "require": { "php": ">=7.2.0", "curl/curl": "^1.6" //这是须要安装的包 } "config": { // 不要.git文件夹 "preferred-install": "dist" } }
执行composer install/update安装php
本身在github/gitlab上建立了一个项目地址是:https://github.com/test/test
此项目的compoesr.json文件中须要定义名字,详细内容以下:html
{ // 注意,这里定义的名字,和以后被require的时候用到的名字相同,而不是github url的后缀 "name": "test1/test1", "authors": [ { "name": "a", "email": "a@gmail.com" } ], "config": { "preferred-install": "dist", "sort-packages": true, "optimize-autoloader": true, "secure-http": false } }
在须要使用该包的项目中建立composer.json,内容以下:git
{ "name": "aaa/bbb", "authors": [ { "name": "a", "email": "a@gmail.com" } ], "require": { "test1/test1": "dev-master" }, "repositories": [ { "type": "vcs", // 这个地址填该项目的链接地址 "url": "https://github.com/test/test" } ], "config": { "preferred-install": "dist", "sort-packages": true, "optimize-autoloader": true, "secure-http": false } }
执行`composer install`就能够安装本身的包了,而不是从packagist上安装
参考:https://github.com/composer/satis
二者均可以安装包,区别有: `install`会读取composer.lock文件,根据缓存的指定版本进行安装,若是没有,则会在安装完毕后建立; `update`不会读取composer.lock文件,而是升级某个包或者全部包,并更新composer.lock文件 因此对于生产环境,推荐使用`composer install`