satis
satis 是一個靜態的 composer 代碼庫生成器。他可以提供私有資源包更新服務;
安裝
首先保證已經安裝了composer;
然後到web根目錄;
composer create-project composer/satis --stability=dev --keep-vcs
執行完畢之後,會生成一個satis目錄;然後創建satis配置文件
vim satis/satis.json
配置文件內容;
{
"name": "something",
"homepage": "http://packages.local.com",
"repositories": [
{"type": "vcs", "url": "something.git"}
],
"require":{
"something":"*"
},
"archive":{
"directory":"dist",
"format":"tar",
"prefix-url":"http://packages.local.com/",
"skip-dev":true
}
}
在 repositories 裏面即爲私有資源包,裏面url可以使用內網git地址;
PS:私有資源包裏面必須要有composer.json文件;如果項目沒有composer依賴使用,可以建立一個簡單的composer.json文件;如下:
{
"name": "name",
"description": "description",
"license": "MIT",
"authors": [
{
"name": "name",
"email": "[email protected]"
}
],
"require":{
"php":">=7.0.0"
}
}
使用下面的命令既可以生成私有庫站點;
php bin/satis build satis.json public/
這裏執行完畢之後,配置web服務器,將配置文件 satis.json 裏面 homepage 的域名配置到web服務器;
nginx的配置文件如下:
server {
listen 80;
server_name packages.local.com;
root /data/www/satis/public;
index index.php index.html index.htm;
access_log /tmp/nginx/packages.local.com.access.log;
error_log /tmp/nginx/packages.local.com.error.log;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php($|/) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
然後在瀏覽器裏面訪問配置的域名packages.local.com就可以訪問私有庫了;
顯示如下:
這時候在satis的站點裏面就能看到我們的私有資源包了;
使用
在項目裏面就可以獲取私有庫裏面的資源包了;
在項目裏面的 composer.json 裏面增加
"repositories": {
"packages": {
"type": "composer",
"url": "http://packages.local.com"
},
"packagist": {
"type": "composer",
"url": "https://packagist.phpcomposer.com"
}
},
"require": {
"yourpackage": "~1.0",
"php": ">=7.0.0"
}
然後執行composer update 就可以獲取到私有庫裏面的包了;
repositories 裏面的配置項是所有資源包的更新站點,可以配置多個,composer會遍歷尋找資源包的;
這裏配置的是http的庫站點,如果更新出錯需要執行下面命令,將composer允許更新非https的站點;
composer config -g secure-http false