Productive Environment for PHP Teams - II

Previous post shown the reasons to host a local Composer repository. This will show the code to accomplish that point.

Let’s get dirty!

Setting up a local Composer respository

Install Composer

If you didn’t previously:

1
2
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

Install Satis

1
2
composer create-project composer/satis --stability=dev
cd satis

At this point you can generate a package.json through Satis in order to use a local repository. To generate a Composer-repo from a Git-repo the only requirement is to have a valid composer.json on the root folder at master branch.

Add a composer.json file to your Git repo

Composer helps you to do this:

1
composer init

Generate a Composer-repo from your Git-repo

All you need is to edit a satis.json file

satis.json
1
2
3
4
5
6
7
8
9
10
11
12
{
    "name": "jhvaras/example",
    "homepage": "http://example.local",
    "description": "Example description here",
    "repositories": [
        {
            "type": "vcs",
            "url": "/path/to/the/git/repository"
        }
    ],
    "require-all": true
}

And generate the Composer repo:

1
bin/satis build satis.json /path/to/the/composer/repository

And you are done!!!

Install from your Composer repository

Edit your composer.json, add your require package name and the local repo, which you can publish through http in order to be accesed locally:

your-project/composer.json
1
2
3
4
"require":{
        "jhvaras/example":"dev-master"
    },
"repositories": [ { "type":"composer", "url":"http://your_composer_repo.local" } ]

You can avoid coping the repositories line by adding the repository to the default reposiitories:

~/.composer/config.json
1
2
3
4
5
6
7
8
{
    "repositories": [
        {
            "type":"composer",
            "url":"http://git.local2"
        }
    ]
}

Improving the environment

This is quite complex just to get a private Composer repo, so next post in this serie will cover how to automate this tasks, and get a local GitHub working.

Comments