Andrei Pall

Linux Software Engineering

How to use Composer

Install Composer Globally

Composer requires PHP 5.3.2+ to run. A few sensitive php settings and compile flags are also required, but the installer will warn you about any incompatibilities.

To install packages from sources instead of simple zip archives, you will need git, svn or hg depending on how the package is version-controlled.

You can run these commands to easily access composer from anywhere on your system:

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

Packagist is the main Composer repository. It aggregates all sorts of PHP packages that are installable with Composer. To install Mustache create the file composer.json:

{
  "require": {
    "mustache/mustache": "2.7.0"
  }
}

and run the command:

composer install

To use this package in our project create a file test.php with the content:

<?php
require_once "vendor/autoload.php"

$mustache = new Mustache_Engine();

echo $mustache->render("Hello ", ["name" => "Andrei"]);
?>

To update a Composer package run:

composer update
Create project with Composer
composer search laravel
composer create-project laravel/laravel

cd laravel
php artisan serve


composer show slim/slim
composer create-project slim/slim slim-2.4.0 2.4.0