使用satis 搭建 自己composer 代码库 教程02

前面已经说了如何使用composer,以及配合使用 packagist 搭建代码库;
本章要讲的是 用自己的服务器使用 satis 搭建私人的代码库


1、 Satis 是一个静态的 composer 代码库生成器

$ composer.phar create-project composer/satis --stability=dev

2、在当前目录下会有一个文件夹 satis

$ cd satic
$ vim satis.json

我的 satis.json 文件配置

{
    "name": "Nothing",
    "homepage": "http://packagist.xxx.top",
    "repositories": [
        { 
            "type": "vcs", "url": "https://gitee.com/liulonghai/test.git",
            "type": "vcs", "url": "https://gitee.com/liulonghai/Helper.git"
        }
    ],
   "require": {
        "xiaoliu/test": "*",
        "nothing/helper": "*"
    }
}

简单说一下 
name : 是名称 可以随便取
homepage : 是在satis上显示的默认私有镜像地址
repositories:需要被索引的git代码仓库地址,而我用的是码云,所以把地址复制下来即可
require:就是你要导入的包名 以及版本  我这里是 * 表示所以发布的包我都加入

3、使用 satis.json 配置来构建我们的代码库 输出到web目录下

$ php bin/satis build satis.json web
    [web是我们输出的目录] 后面加上 -v 参数可以看到被索引的包

error:
01:  PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 88 bytes) in /data/wwwroot/satis/vendor/composer/composer/src/Composer/Repository/ComposerRepository.php on line 566
     Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 88 bytes) in /data/wwwroot/satis/vendor/composer/composer/src/Composer/Repository/ComposerRepository.php on line 566

02、把php.ini     memory_limit 修改成512M 即可

03、如果不知道php.ini在哪里 可以使用 php --ini

04、其他错误则根据错误提示去解决

4、配置一下nginx

  server {
    listen 80;
    server_name packagist.xxx.top;
    access_log /data/wwwlogs/satis.log combined;
    #root /data/wwwroot/default;
    root /data/wwwroot/satis/web;
    index index.html index.htm index.php;
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    location /nginx_status {
      stub_status on;
      access_log off;
      allow 127.0.0.1;
      deny all;
    }
    location ~ [^/]\.php(/|$) {
      #fastcgi_pass remote_php_ip:9000;
      fastcgi_pass unix:/dev/shm/php-cgi.sock;
      fastcgi_index index.php;
      include fastcgi.conf;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
      expires 30d;
      access_log off;
    }
    location ~ .*\.(js|css)?$ {
      expires 7d;
      access_log off;
    }
    location ~ /\.ht {
      deny all;
    }
  }

5、配置成功 打开一下 packagist.xxx.top 网址就会看到如下的页面

安装成功页面

6、下载我们的新包 修改composer.json 文件

{
  "repositories": [{
    "type": "composer",
    "url": "http://packagist.xxx.top"
  }],
  "require":{
    "xiaoliu/test":"3.0",
    "nothing/helper":"1.0.2"
  }
}
$ composer update 
// 成功即可 已经冲我们自己的服务器下载了这些包 使用即可

如果报错
Your configuration does not allow connections to http://packagist.xxx.top/packages.json. See https://getcomposer.org/doc/06-config.md#secure-http for details
则在服务器上执行
composer config -g secure-http false

意义是默认禁用https请求,就可以了

7、优化 satis.json 从我们自己的服务器上下载包

{
    "name": "Nothing",
    "homepage": "http://packagist.xxx.top",
    "repositories": [
        { 
            "type": "vcs", "url": "https://gitee.com/liulonghai/test.git",
            "type": "vcs", "url": "https://gitee.com/liulonghai/Helper.git"
        }
    ],
   "require": {
        "xiaoliu/test": "*",
        "nothing/helper": "*"
    },
    "archive": {
        "directory": "dist",
        "format": "tar",
        "prefix-url": "http://packagist.xxx.top",
        "skip-dev": true
    }
}
    你会发现我们之前的配置 update 会比较慢 那是因为我们下载资源的时候都是从托管平台下下载的,添加这个则表示update 将从我们自己的服务器上下载,速度会快许多
    archive 存档在自己的服务器上
        -- directory 代码包存放的文件夹
        -- format 压缩的格式 默认是zip 我选择的是tar
        -- prefix-url 可选的。下载的地址 不填默认是 homepage 【satis.json】 的值
        -- skip-dev 默认是false 是否跳过开发分支

7、到这里就完成了。注意 每次更新了新的包 要来到satis 执行 php bin/satis build satis.json web


借鉴 : http://docs.phpcomposer.com/articles/handling-private-packages-with-satis.html

猜你喜欢

转载自blog.csdn.net/qq_16142851/article/details/78677962