Home  >  Article  >  Development Tools  >  [php] How to use composer to automatically verify and obtain gitlab's private library at the same time

[php] How to use composer to automatically verify and obtain gitlab's private library at the same time

little bottle
little bottleforward
2019-04-19 09:32:083730browse

The main content of this article is about using composer to automatically verify and obtain the private library of gitlab at the same time. Interested friends can learn about it.

After recently purchasing Laravel’s nova, I need to make some modifications to its core code to facilitate sharing with other team members and to facilitate difference management after the nova official library is updated. Then hang the nova library in your own gitlab and reference it directly through composer.

Related recommendations: [composer tutorial]

Gitlab is full of private libraries. Composer access requires authentication. Enter the username/password during local testing. Authentication does not matter, but deployment on the production server is problematic. Since it is an automatic deployment, it must be fully automatic. After some trouble, composer can complete the verification by configuring GitLab's Private Token and obtain the private library without having to enter the username and password.

To facilitate the description of the operation process. Here we take the official package laravel/nova as an example. I put laravel/nova on my own gitlab, the path is https://git.papamk.com/xxx/nova, and set it as a private library. Our goal is that composer can directly obtain the package without entering a password.

Configuration process

1. Generate Private Token

On gitlab, find `Access in `User Settings` Tokens`, see the picture below:

⚠️⚠️⚠️: The generated token is only displayed once, remember to save it and use it later.

[php] How to use composer to automatically verify and obtain gitlabs private library at the same time

2. Configure composer’s authentication information

Edit ~/.composer/auth.json (If there is no such file, create it directly)


 1 { 2     "bitbucket-oauth": {}, 3     "github-oauth": {}, 4     "gitlab-oauth": { 5     }, 6     "gitlab-token": { 7       "git.papamk.com": "" 8     }, 9     "http-basic": {},10     "gitlab-domains":["git.papamk.com"]11 }

Notes:

  • Unless you are using gitlab.com, you should add the domain name of gitlab to gitlab-domains;

3. Edit composer .json


{    // ...省略其他部分
    "repositories": [
      {        "type": "gitlab",        "url": "https://git.papamk.com/xxx/nova"
      }
    ],    "require": {        // ...省略其他包
        "laravel/nova": "dev-master",
    }
}

Key points:

  • type: must be gitlab
  • Package name: official package name For laravel/nova, you still need to use laravel/nova here, not xxx/nova

Now you are done, run composer install or composer udpate to try.

Other issues

There may be a problem that the configuration is correct, but the package is read directly from the local cache. At this time, just delete ~/.composer/cache and try again.

Related tutorials: php from entry to proficiency

The above is the detailed content of [php] How to use composer to automatically verify and obtain gitlab's private library at the same time. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete