Laravel 5.x Cookbook
上QQ阅读APP看书,第一时间看更新

Using private packages

Sometimes, you need to use a private repository on GitHub or another location. I will cover here how to set this up in your composer.

Getting ready

We need a private repo, so if you have it and its composer.json is set up properly, you will be set from there.

How to do it...

  1. First, go to GitHub and navigate to SettingsPersonal access tokens:
  2. At the command line, type this:
    >composer config –g github-oauth.github.com THE_TOKEN_FROM_ABOVE. 
  3. Then, edit composer.json so that there are two new sections:
  4. Then, let's tell the composer to install this:
    >rm –rf composer.lock vendor
    >composer install
    

How it works...

Alright, let's talk about these steps. The first one is to make sure we are setting up our Homestead or Mac for easy access to the private repository. This is really key as well if you are doing 2FA on your GitHub account (which you should be doing). Step 2 wraps this up by adding it to your ~/.composer configuration.

In the next part, we edit the composer.json file; and here, we see just how powerful Composer really is. It uses conventions and Packagist to easily organize and pull in projects; it also allows you to override this information in the repositories section of the file. Since the repository will not be in Packagist as it is private, the Composer will need to know where to look and this is made possible by this section.

Finally, I do install since I feel it is faster. You can update it or you can do whatever is required as well.

That's it, you will now see this private repository in your vendor/ folder.

See also