Satis 是一个由 Composer 团队开发的静态包仓库生成器,用于构建企业级私有 PHP 包管理系统。它将指定的私有 Composer 包(如 Git 仓库)编译为 JSON 文件集合,通过 Web 服务器提供类似 Packagist 的安装体验。相比直接使用 VCS 地址,Satis 提供更高效、安全、集中化的管理方式,适合中大型团队或对代码保密性要求高的企业。核心优势包括支持私有包托管、生成静态文件便于部署、与 Composer 完全兼容、可集成身份验证和 CI/CD 流程,并支持镜像 GitHub、GitLab、Bitbucket 等多种源。搭建步骤包括:准备 PHP、Composer、Git 和 Web 服务器环境;全局或本地安装 Satis;配置 satis.json 定义仓库源和输出目录;运行 php bin/satis build 生成静态文件;配置 Nginx 指向输出目录并启用 HTTPS 与认证;在项目 composer.json 中添加私有仓库地址并使用 composer install 安装包。建议结合 CI/CD 或 cron 定时重建仓库以保持同步,同时注意 SSH 密钥或访问令牌的配置以避免权限问题。

Satis 是一个由 Composer 团队开发的静态包仓库生成器,用于构建企业级私有 PHP 包管理系统。它能将你指定的 Composer 包(如私有 Git 仓库)编译成一个可访问的 JSON 文件集合,并通过 Web 服务器对外提供服务,使团队可以像使用 Packagist 一样安装私有包。
相比直接在项目中引用 VCS 地址,Satis 提供了更高效、安全和集中化的管理方式,适合中大型团队或对代码保密性要求较高的企业环境。
核心优势:
1. 准备服务器环境
确保服务器已安装以下组件:
示例命令(Ubuntu):
sudo apt update sudo apt install php-cli git zip unzip nginx curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
2. 安装 Satis
执行以下命令全局安装 Satis:
composer global require composer/satis
或将 Satis 克隆到项目目录中管理:
git clone https://github.com/composer/satis.git cd satis && composer install
3. 配置 satis.json
在项目根目录创建 satis.json 文件,定义你的包源和输出设置:
{
"name": "My Private Package Repository",
"homepage": "https://packages.example.com",
"repositories": [
{
"type": "vcs",
"url": "git@gitlab.company.com:team/private-lib.git"
},
{
"type": "vcs",
"url": "https://github.com/company/internal-sdk"
}
],
"require-all": true,
"output-dir": "web/"
}
关键字段说明:
若只发布特定包,使用 "require": {"vendor/package": "dev-main"} 明确声明。
4. 生成静态仓库
运行构建命令:
php bin/satis build satis.json
成功后会在 web/ 目录下生成 index.html 和 packages.json 等文件。
5. 配置 Web 访问
将 Nginx 的 root 指向 web/ 目录:
server {
listen 80;
server_name packages.example.com;
root /path/to/satis/web;
index index.html;
<pre class='brush:php;toolbar:false;'>location / {
try_files $uri $uri/ =404;
}}
启用 HTTPS 并配置基本认证增强安全性。
6. 在项目中使用私有仓库
在需要安装私有包的项目的 composer.json 中添加仓库:
{
"repositories": [
{
"type": "composer",
"url": "https://packages.example.com"
}
],
"require": {
"company/private-lib": "^1.0"
}
}
然后执行:
composer install
首次可能提示认证失败,需配置 SSH 密钥或添加 GitHub/GitLab 的个人访问令牌(PAT)到 Composer 配置:
composer config --global github-oauth.github.com YOUR_TOKEN # 或 GitLab composer config --global gitlab-token.gitlab.com YOUR_TOKEN
为了保持私有仓库同步最新代码,推荐结合以下方式自动重建:
satis build
例如添加定时任务:
# 每天凌晨2点更新 0 2 * * * cd /path/to/satis && php bin/satis build satis.json
权限拒绝(SSH):确保运行 Satis 的用户拥有正确的 SSH 私钥,并添加公钥到 Git 服务中。
无法克隆仓库:检查 URL 是否正确,是否使用了支持的身份验证方式(SSH 或 Token)。
包未出现在 packages.json:确认是否启用了 require-all,或已在 require 中明确列出。
基本上就这些。Satis 虽然功能简洁,但足以支撑企业级私有包管理需求,搭配自动化流程后维护成本很低。关键是做好权限控制和部署安全。
以上就是什么是Satis以及如何搭建私有Composer仓库_企业级私有Composer包管理方案Satis搭建教程的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号