在咱们的平常php开发中可能须要使用大量的composer包,大部份均可以直接使用,但在公司内部总有一小部份包是不能公开的,这时候咱们就须要搭建一个公司内部使用的composer仓库,好在composer官方有提供这样的工具satis和toran proxy,satis搭建相对简单一些,咱们今天就选用satis进行。php
cd /data/www/ composer create-project composer/satis --stability=dev --keep-vcs mv satis packages.dev.com cd packages.dev.com
satis的配置是经过satis.json进行的,咱们在当前目录新建一个satis.json。html
{ "name": "My Repository", "homepage": "http://packages.dev.com", "repositories": [ {"type": "vcs", "url": "http://git.dev.com/maxincai/package1.git"}, {"type": "vcs", "url": "http://git.dev.com/maxincai/package1.git"}, ], "require": { "maxincai/package1": "*", "maxincai/package2": "*", } }
咱们简单解释一下这个json文件nginx
使用命令:php bin/satis build
咱们生成的时候通常会生成html和paceages.json文件github
php bin/satis build satis.json public/
若是只须要生成某几个包,则能够在后面增长包的名字web
php bin/satis build satis.json web/ this/package that/other-package
使用上面的命令不出意久的会就会在public目录下生成相应的文件,若是出错,根据错误提示去解决便可,经常使用的问题多是权限问题,或是git版本太低等。json
为了使咱们的生成的内容能够访问,咱们能够简单的使用php内置的服务器启动一个简单的服务器。缓存
php -S 0.0.0.0:8088 -t public/
这样经过127.0.0.1:8088就能够进行访问了,大概会看到相似下面这样的画面
服务器
不过咱们是为了稳定使用的,因此使用nginx作为咱们的web服务器,配置以下:composer
server { listen 80; server_name packages.dev.com; root /data/www/packages.dev.com/public; index index.php index.html; access_log /var/log/nginx/packages.dev.com.log main; error_log /var/log/nginx/packages.dev.com.log.err debug; rewrite_log on; location ~* \.php$ { #try_files $uri $uri/ /index.php?$query_string; #try_files $uri =404; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/var/run/php-cgi.sock; fastcgi_index index.php; } location = /favicon.ico { log_not_found off; access_log off; } }
修改Host packages.dev.com至127.0.0.1以后,咱们就能够经过packages.dev.com进行访问了。
经过上面的配置后,咱们就能够在项目中使用了,只需简单的修改composer.json文件
{ "repositories": [ { "type": "composer", "url": "http://packages.dev.com/" } ], "require": { "company/package": "1.2.0", "company/package2": "1.5.2", "company/package3": "dev-master" } }
而后执行composer update便可
经过上面的例子你会发现composer update的时候会去咱们的git中clone,有时候会比较慢,咱们并不但愿每次都clone,其实咱们也能够缓存在咱们的仓库中,这样每次update的时候就只用下载了。
在satis.json中增长
{ "archive": { "directory": "dist", "format": "tar", "prefix-url": "http://packages.dev.com/", "skip-dev": true } }
参数说明:
再次生成
php bin/satis build satis.json public/
会发现public目录多了一个dist目录,里面有不少tar的压缩包,这就是咱们的package。
以后再执行composer update
就会发现快了不少。
一个公司内部的composer仓库就完成了。
https://getcomposer.org/doc/articles/handling-private-packages-with-satis.md
http://www.netfoucs.com/article/qq280948982/99039.html