Forge Home

php_phars

A module to install PHARS: composer.phar, phpunit.phar, etc.

14,161 downloads

8,978 latest version

3.1 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Support the Puppet Community by contributing to this module

You are welcome to contribute to this module by suggesting new features, currency updates, or fixes. Every contribution is valuable to help ensure that the module remains compatible with the latest Puppet versions and continues to meet community needs. Complete the following steps:

  1. Review the module’s contribution guidelines and any licenses. Ensure that your planned contribution aligns with the author’s standards and any legal requirements.
  2. Fork the repository on GitHub, make changes on a branch of your fork, and submit a pull request. The pull request must clearly document your proposed change.

For questions about updating the module, contact the module’s author.

Version information

  • 0.2.1 (latest)
  • 0.2.0
  • 0.1.8
  • 0.1.7
  • 0.1.4
  • 0.1.3
  • 0.1.2
  • 0.1.1
  • 0.1.0
released Aug 27th 2015
This version is compatible with:
  • Puppet 3.7.x

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'gajdaw-php_phars', '0.2.1'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add gajdaw-php_phars
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install gajdaw-php_phars --version 0.2.1

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

gajdaw/php_phars — version 0.2.1 Aug 27th 2015

php_phars Puppet Module

Table of Contents

  1. Overview
  2. Module Description
  3. Setup
  4. Usage
  5. Reference
  6. Limitations
  7. Development
  8. Inspiration

Overview

This module php_phars aims to simplify the installation of PHAR applications, like composer, phpunit, php-cs-fixer, etc.

Module Description

In general:

  • the module downloads a file to an arbitrary directory
  • sets the owner
  • sets the rights

It can be seen as a sequence of three:

  • wget
  • chown
  • chmod

commands.

The module contains a build-in catalog of well-known PHARS, like composer, phpunit, php-cs-fixer. Thus, you don't have to care about their URLs.

You can install:

  • all PHARS from the catalog
  • only those PHARS from the catalog that you need
  • user defined PHARS

The catalog is an array named $catalog: defined in manifests/params.pp file. This array is shown in Reference.

Setup

What php_phars affects

Module:

  • downloads files (e.g. https://getcomposer.org/composer.phar)
  • saves them under a given name (e.g. composer) in an arbitrary directory (e.g. /usr/local/bin)
  • sets the owner (e.g. root)
  • sets the rights (e.g. a+x)

This operation can be executed:

  • all PHARS from the catalog
  • only chosen PHARS from the catalog
  • user defined PHARS

Setup Requirements

The module uses:

Beginning with php_phars

System wide install with Puppet

To install the module in your system run:

sudo puppet module install gajdaw-php_phars

You may lock the version to avoid using the latest version:

sudo puppet module install gajdaw-php_phars --version 0.1.0

System wide install with Git

You may also use git to install the module:

mkdir -p /etc/puppet/modules/php_phars
cd /etc/puppet/modules/php_phars
git clone --depth 1 https://github.com/puppet-by-examples/puppet-php_phars.git .

To lock the version, use:

git clone --depth 1 --branch v0.1.0 https://github.com/puppet-by-examples/puppet-php_phars.git .

Usage

For a more complete list of examples refer to examples/ directory.

Install all PHARS from the catalog

# Filename: examples/all.pp

class { 'php_phars':
    all => true,
}

You can run the example with:

sudo puppet apply examples/all.pp

The command will install all PHARS:

/usr/local/bin/composer
/usr/local/bin/phpunit
/usr/local/bin/php-cs-fixer
/usr/local/bin/box
/usr/local/bin/behat
/usr/local/bin/phpspec
/usr/local/bin/symfony

By default: PHARS are not redownloaded. Thus, when you run the command again and again:

sudo puppet apply examples/all.pp
sudo puppet apply examples/all.pp

nothing happens. To force redownload use redownload parameter.

Install/Update all PHARS from the catalog

# Filename: examples/all-redownload.pp

class { 'php_phars':
    all        => true,
    redownload => true,
}

You can run the example with:

sudo puppet apply examples/all-redownload.pp

This example redownloads PHARS every time you run it.

Install composer and phpunit only

# Filename: examples/only-composer-phpunit.pp

class { 'php_phars':
    phars      => ['composer', 'phpunit'],
    redownload => true,
}

You can run the example with:

sudo puppet apply examples/only-composer-phpunit.pp

Install all PHARS from the catalog and one special file

# Filename: examples/append-all.pp

class { 'php_phars':

    all => true,

    append => [
        {
            'app' => 'symvirins',
            'url' => 'https://raw.githubusercontent.com/karlosagudo/symvirins/master/symvirins.phar'
        }
    ],

}

You can run the example with:

sudo puppet apply examples/append-all.pp

The command will install all PHARS from the catalog and:

/usr/local/bin/symvirins

Running phar binaries (phpunit, composer, etc.)

If php is missing, install it with:

sudo apt-get install php5 -y

Now, you can use the binaries:

composer --version
phpunit --version
php-cs-fixer --version
box --version
behat --version
phpspec --version
symfony --version

Uninstall

Currently, to uninstall files, you have to use rm command:

sudo rm /usr/local/bin/composer
sudo rm /usr/local/bin/phpunit
sudo rm /usr/local/bin/php-cs-fixer
sudo rm /usr/local/bin/box
sudo rm /usr/local/bin/behat
sudo rm /usr/local/bin/phpspec
sudo rm /usr/local/bin/symfony

Reference

The complete list of parameters is available in manifests/fetch.pp file.

The catalog is an array of hashes:

# Filename: manifests/params.pp

...

$catalog = [
    {
        'app' => 'composer',
        'url' => 'https://getcomposer.org/composer.phar'
    },
    {
        'app' => 'phpunit',
        'url' => 'https://phar.phpunit.de/phpunit.phar'
    },
    {
        'app' => 'php-cs-fixer',
        'url' => 'http://cs.sensiolabs.org/get/php-cs-fixer.phar'
    },
    {
        'app' => 'box',
        'url' => 'https://github.com/box-project/box2/releases/download/2.5.0/box-2.5.0.phar'
    },
    {
        'app' => 'behat',
        'url' => 'https://github.com/Behat/Behat/releases/download/v3.0.14/behat.phar'
    },
    {
        'app' => 'phpspec',
        'url' => 'https://github.com/phpspec/phpspec/releases/download/2.1.1/phpspec.phar'
    },
    {
        'app' => 'symfony',
        'url' => 'http://symfony.com/installer'
    }
]

The catalog contains the following PHARS:

Limitations

The module was tested on:

  • Ubuntu
    • 12.04 / Puppet 3.7 (Vagrant box: ubuntu/precise32)
    • 14.04 / Puppet 3.7 (Vagrant box: ubuntu/trusty32)
  • CentOS
    • 6.5 / Puppet 3.7 (Vagrant box: puppetlabs/centos-6.5-64-puppet)
    • 7.0 / Puppet 3.7 (Vagrant box: puppetlabs/centos-7.0-64-puppet)
  • Debian
    • 6.0 / Puppet 3.7 (Vagrant box: chef/debian-6.0.8)
    • 7.4 / Puppet 3.7 (Vagrant box: chef/debian-7.4)
  • Fedora
    • 20 / Puppet 3.7 (Vagrant box: chef/fedora-20)

How to test this module?

Boot the VM:

$ vagrant up

Update Puppet to version 3.7.

Create symbolic links:

$ cd /vagrant
$ ./symlinks.sh

Install dependencies:

$ sudo puppet module install puppetlabs-stdlib
$ sudo puppet module install maestrodev/wget

Run:

$ sudo puppet apply modules/puppet-php_phars/examples/only-composer-phpunit.pp

Install PHP.

Run:

$ composer --version
$ phpunit --version

Development

For development instructions visit Puppet Modules Factory

Inspiration

The inspiration came from willdurrand-composer puppet module authored by William Durand.