debian + Composer

Screenshot 2014-09-25 at 02.12.20




  • プロジェクト(ディレクトリ)ごとにパッケージをインストール可能、そのためプロジェクトごとにあるライブラリのバージョンをわけることが可能。(PEARはOS全体に影響する)
  • クラスオートローディング(クラスが使われているとそれに応じたファイルを自動的に読みこむ)機能が利用可能。requireやincludeなどを記述しなくてよくなる


root@hostname:/usr/local/sbin# curl -sS | php
bash: php: コマンドが見つかりません
bash: curl: コマンドが見つかりません
root@hostname:/usr/local/sbin# aptitude install  curl php5-cli
  curl php5-cli
root@hostname:/usr/local/sbin# curl -sS | php # -s:不要なプログレスメータを出力しない
#!/usr/bin/env php
All settings correct for using Composer

Composer successfully installed to: /usr/local/sbin/composer.phar
Use it: php composer.phar
root@hostname:/usr/local/sbin# ls | grep composer
root@hostname:/usr/local/sbin# cd /var/www/
### パッケージの定義ファイル(composer.json)を作成 ###
root@hostname:/var/www/ vi composer.json
    "require": {
        "monolog/monolog": "1.2.*"
### composer.jsonファイルを読み込み、依存パッケージなどのインストールを実施する ###
oot@hostname:/var/www/ /usr/local/sbin/composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing monolog/monolog (1.2.1)
    Downloading: 100%         

monolog/monolog suggests installing mlehner/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
Writing lock file
Generating autoload files
root@hostname:/var/www/ tree -L 2
├── composer.json
├── composer.lock # インストールされたバージョンを記録する
└── vendor # パッケージのインストール先
    ├── autoload.php
    ├── composer
    └── monolog

3 directories, 3 files


### helpの表示 ###
root@hostname:/var/www/ /usr/local/sbin/composer.phar -help
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
Composer version eba04dc211f794d6f3a5500cfcfb9f9c0efcefbc 2014-09-24 13:38:16

  [options] command [arguments]

  --help           -h Display this help message.
  --quiet          -q Do not output any message.
  --verbose        -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
  --version        -V Display this application version.
  --ansi              Force ANSI output.
  --no-ansi           Disable ANSI output.
  --no-interaction -n Do not ask any interactive question.
  --profile           Display timing and memory usage information
  --working-dir    -d If specified, use the given directory as working directory.

Available commands:
  about            Short information about Composer
  archive          Create an archive of this composer package
  browse           Opens the package's repository URL or homepage in your browser.
  clear-cache      Clears composer's internal package cache.
  clearcache       Clears composer's internal package cache.
  config           Set config options
  create-project   Create new project from a package into given directory.
  depends          Shows which packages depend on the given package
  diagnose         Diagnoses the system to identify common errors.
  dump-autoload    Dumps the autoloader
  dumpautoload     Dumps the autoloader
  global           Allows running commands in the global composer dir ($COMPOSER_HOME).
  help             Displays help for a command
  home             Opens the package's repository URL or homepage in your browser.
  init             Creates a basic composer.json file in current directory.
  install          Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
  licenses         Show information about licenses of dependencies
  list             Lists commands
  remove           Removes a package from the require or require-dev
  require          Adds required packages to your composer.json and installs them
  run-script       Run the scripts defined in composer.json.
  search           Search for packages
  self-update      Updates composer.phar to the latest version.
  selfupdate       Updates composer.phar to the latest version.
  show             Show information about packages
  status           Show a list of locally modified packages
  update           Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  validate         Validates a composer.json

### composerのバージョン確認 ###
root@hostname:/var/www/ /usr/local/sbin/composer.phar -V
Composer version eba04dc211f794d6f3a5500cfcfb9f9c0efcefbc 2014-09-24 13:38:16

### composerが最新か確認する ###
root@hostname:/var/www/ /usr/local/sbin/composer.phar self-update
You are already using composer version eba04dc211f794d6f3a5500cfcfb9f9c0efcefbc.

### インストールされているパッケージ一覧を参照する ###
root@hostname:/var/www/ /usr/local/sbin/composer.phar show -i
monolog/monolog 1.2.1 Logging for PHP 5.3

### パッケージを指定してバージョンアップする ###
root@hostname:/var/www/ /usr/local/sbin/composer.phar update monolog/monolog
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files

### パッケージのバージョンアップ後、composer.lockを更新する ###
root@hostname:/var/www/ /usr/local/sbin/composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files

### パッケージを検索する ###
root@hostname:/var/www/ /usr/local/sbin/composer.phar search CakePHP
cakephp/cakephp The CakePHP framework
cakephp/cakephp-codesniffer CakePHP CodeSniffer Standards
cakephp/debug_kit CakePHP Debug Kit
cakephp/app CakePHP skeleton app
cakephp/localized CakePHP Localized Plugin
cakephp/migrations Database Migration plugin for CakePHP 3.0 based on Phinx
cakephp/datasources CakePHP Datasources Plugin
cakephp/monolog CakePHP Monolog Plugin
cakephp/collection Work easily with arrays and iterators by having a battery of utility traversal methods
cakephp/plugin-installer A composer installer for CakePHP 3.0+ plugins.
friendsofcake/cakephp-test-utilities Package with support traits to ease unit testing.
cakephp/acl Acl Plugin for CakePHP 3.x framework
imsamurai/cakephp-advancedshell Advanced feutures for cakePHP shell
imsamurai/cakephp-environment Provides improovement for tests, packagist, etc
renan/cakephp-xhprof Plugin that quickly enables XHProf profiling for your CakePHP application.

### パッケージの詳細情報を表示する ###
root@hostname:/var/www/ /usr/local/sbin/composer.phar show cakephp/cakephp
name     : cakephp/cakephp
descrip. : The CakePHP framework
keywords : framework
versions : dev-master, 3.0.x-dev, 3.0.0-beta1, 3.0.0-alpha2, 3.0.0-alpha1, 2.6.x-dev, 2.5.4, 2.5.3, 2.5.2, 2.5.1, 2.5.0, 2.5.0-RC2, 2.5.0-RC1, 2.5.0-beta, 2.4.x-dev, 2.4.10, 2.4.9, 2.4.8, 2.4.7, 2.4.6, 2.4.5, dev-3.0-psr-3, dev-3.0-buffered-iterator, dev-3.0-asset-filter, dev-3.0-sumby, dev-3.0-inflector, dev-3.0-use, dev-3.0-debug, dev-3.0-casing, dev-3.0-inflect-bug, dev-3.0-new-bake-templates, dev-3.0-translate-behavior-fix, dev-3.0-hhvm-take2, dev-3.0-method-rename, dev-3.0-windows-tests, dev-3.0-nest-label, dev-issue-4671, dev-issue-4664-webroot, dev-issue-4641, dev-issue-4616, dev-issue-3600, dev-master-email, dev-table-find-or-create
type     : library
license  : MIT
source   : [git] eac4e3d6eeb6d90dfc237e745ba7298271280346
dist     : [zip] eac4e3d6eeb6d90dfc237e745ba7298271280346
names    : cakephp/cakephp

php >=5.2.8
ext-mcrypt *

requires (dev)
phpunit/phpunit 3.7.*
cakephp/debug_kit 2.2.*

Screenshot 2014-09-25 at 01.59.53