The Composer tool, used by PHP community, has deeply modified the habits of many PHP designers, carrying a great simplification in the management of dependencies in PHP applications.

The only problem with such management is that it has made mandatory the use of Packagist: a container for all open source projects developed by PHP community. 

What if the client doesn't like to release open source codes? What if the designer provider has foreseen to apply costs for the whole bandwidth used by servers?

And more: How many of you have ever come across this error message?

 

The Composer designers were able to solve these problems: the solution is represented by Satis, an open source project, allowing the creation of a repository mirror inside your local network.

Now let's have a detailed look at installation and operation of such solution. 

The installation requires the execution of this simple command.

php composer.phar create-project composer/satis --stability=dev --keep-vcs

Composer, using the “create-project” command, takes care to clone the project repository and download the libraries needed for its operation. 

After this step, you can configure the system:

{
    "name": "Spaghetti.io - Satis",
    "homepage": "http://packages.spaghetti.io",
    "repositories": [
        { "type": "vcs", "url": "https://github.com/Seldaek/monolog" },
        {"type":"vcs", "url": "https://github.com/swiftmailer/swiftmailer.git"}
    ],
    "require-all": true
}

the configuration file (whose default name is satis.json and is stored in the project root) contains useful information, such as the project link and its name, including a list of repositories to be mirrored.

Once you have specified the project dependencies, you need to prepare the packagist build, giving the following command (in project root):

php bin/satis build config.json web/

In such a way, you'll get the web directory, containing files needed for web browsing of your packagist clone, and you'll clone repositories for the classes specified in the configuration file. 

By creating a virtual host pointing to the proper address, or using the php embedded browser to run your project, you can point your browser to the web address of your repository, to see a screen like this:  

To finally use your packagist clone, bypassing packagist, github and bitbucket, you can simply update the Composer configuration files to specify the new server address, as shown in the following:

{
    "repositories": [ 
    	{ "type": "composer", "url": "http://packages.spaghetti.io/" } 
    ],
    "require": {
        "monolog/monolog": "1.10.0",
        "swiftmailer/swiftmaler": "v5.2.1"
        [...]
    }
}

Satis is a very simple tool, incredibly fast to be configured and capable to solve many troubles, heavily increasing the performance for the deployment of PHP applications.  Its mass use is recommended in scalable environments: imagine what would happen if you need to deploy a new VM in your code and github is not available.... 

Antonio Pessolano

Senior Developer at Consoft Sistemi S.p.A. , Website , @apessolano , Linkedin profile
I destroyed my first computer when i was seventeen when i was trying to do a RAM upgrade. I am 33 years old now and i solve problems trying to reduce the average number of problems that i have found!

All articles by Antonio Pessolano

Comments

comments powered by Disqus

cloudparty

Follow Us