composer私有倉庫搭建

安裝satis包

  • cd /home/wwwroot/
  • composer create-project composer/satis --stability=dev --keep-vcs

添加配置文件

  • cd satic
  • vim satis.json添加類似如下內容
{
    "name": "My Repository",
    "homepage": "http://59.110.107.59",
    "repositories": [
        {"type": "vcs", "url": "https://github.com/bambooleaf/reps_demo.git"},
        {"type": "vcs", "url": "https://github.com/isunshines/hello-world.git"}
    ],
    "require":{
        "reps_demo/helloworld":"*",
        "isunshines/hellow-world":"*"
    },
    "archive":{
        "directory":"dist",
        "format":"tar",
        "prefix-url":"http://59.110.107.59/",
        "skip-dev":true
    }
}

配置文件詳解

  • name:倉庫名字
  • homepage:主頁地址
  • repositories:包所在地址
  • require:指定獲取哪些包及對應的版本,獲取所有包使用"require-all": true,與包中composer.json中的名稱相同,不同會出現問題
  • directory: 必需要的,表示生成的壓縮包存放的目錄,會在build時的目錄中
  • format: 壓縮包格式, zip(默認)和tar
  • prefix-url: 下載鏈接的前綴的Url,默認會從homepage中取
  • skip-dev: 默認爲假,是否跳過開發分支
  • absolute-directory: 絕對目錄
  • whitelist: 白名單,只下載哪些
  • blacklist: 黑名單,不下載哪些
  • checksum: 可選,是否驗證sha1

生成站點

  • bin/satis build satis.json ./public

服務配置

  • PHP服務器設置

    • php -S 127.0.0.1:8080 -t ./public
  • Nginx服務配置類似如下內容

    server {
        listen  80;
        server_name 59.110.107.59;
        index index.html index.php;
        root /home/wwwroot/satis/public;
        
        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        access_log  /home/wwwlogs/59.110.107.59-access.log  default_access;
        error_log /home/wwwlogs/59.110.107.59-error.log  error;
    }

查看私有倉庫是否可以訪問

圖片描述

composer配置

  • composer config -g secure-http false

使用私有倉庫包

  • 在自己項目中的composer.json中添加類似如下內容
{
  "repositories": [
      {"type": "composer","url": "http://59.110.107.59"}
  ],
  "config": {
      "secure-http": false
  },
  "require":{
      "reps_demo/helloworld":"*",
      "isunshines/hellow-world":"*"
  }
}
  • 創建項目

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章