Composerをインストールする方法と使い方

Composerは、PHPのライブラリやパッケージを管理するライブラリ依存管理ツールです。
LaravelやCakePHPなどのフレームワーク、CodeSniffer(コードチェックツール)などのツール類をコマンド1行でインストールすることができるようになります。

Composerをインストールする前にPHPのインストールが必要です。

Composerダウンロードページ
https://getcomposer.org/download/


Composer Gitリポジトリ
https://github.com/composer/


Windowsでのインストール
Linux MacOSでのインストール
使い方

Windowsでのインストール

WindowsではComposer-Setup.exeをダウンロードしてインストールするだけでPATHの設定などを含めて完了します。

Composer-Setup.exe ダウンロード
https://getcomposer.org/Composer-Setup.exe

インストール後に設置される場所は下記のパスです。
C:\ProgramData\ComposerSetup\bin

Linux MacOSでのインストール

インストーラーをダウンロードしてcomposer.pharを作成します。
(チェックサムは変更されることがあるのでダウンロードサイトにて最新のコードを参照します。)

インストーラーのダウンロード
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

インストーラーが改ざんされていないことを確認します。
$ php -r "if (hash_file('sha384', 'composer-setup.php') === 'e21205b207c3ff031906575712edab6f13eb0b361f2085f1f1237b7126d785e826a450292b6cfd1d64d92e6563bbde02') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

インストーラーを実行してcomposer.pharを作成します。
$ php composer-setup.php

インストーラーを削除します。
$ php -r "unlink('composer-setup.php');"

実行した階層にcomposer.pharが作成されるので、composerコマンドが使えるように管理者権限でファイルを移動します。

$ sudo mv composer.phar /usr/local/bin/composer

使い方

オプション

オプション説明
-h--helpDisplay help for the given command. When no command is given display help for the list command
指定されたコマンドのヘルプを表示します。コマンドが指定されていない場合は、list コマンドのヘルプを表示します。
-q--quietDo not output any message
メッセージを出力しない
-V--versionDisplay this application version
このアプリケーションのバージョンを表示する
--ansi|--no-ansiForce (or disable --no-ansi) ANSI output
ANSI 出力を強制する (または --no-ansi を無効にする)
-n--no-interactionDo not ask any interactive question
インタラクティブな質問はしないでください
--profileDisplay timing and memory usage information
タイミングとメモリ使用量の情報を表示する
--no-pluginsWhether to disable plugins.
プラグインを無効にするかどうか。
--no-scriptsSkips the execution of all scripts defined in composer.json file.
combos.json ファイルで定義されているすべてのスクリプトの実行をスキップします。
-d--working-dir=WORKING-DIRIf specified, use the given directory as working directory.
指定した場合、指定されたディレクトリを作業ディレクトリとして使用します。
--no-cachePrevent use of the cache
キャッシュの使用を禁止する
-v|vv|vvv--verboseIncrease the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
メッセージの詳細度を上げます: 通常の出力の場合は 1、詳細な出力の場合は 2、デバッグの場合は 3

利用可能なコマンド

コマンド説明
aboutShows a short information about Composer
Composer に関する簡単な情報を表示します
archiveCreates an archive of this composer package
このComposerパッケージのアーカイブを作成します
auditChecks for security vulnerability advisories for installed packages
インストールされているパッケージのセキュリティ脆弱性勧告をチェックします
browse[home] Opens the package's repository URL or homepage in your browser
[home] ブラウザでパッケージのリポジトリ URL またはホームページを開きます
bumpIncreases the lower limit of your composer.json requirements to the currently installed versions
現在インストールされているバージョンに対して、composer.json 要件の下限を引き上げます。
check-platform-reqsCheck that platform requirements are satisfied
プラットフォーム要件が満たされていることを確認する
clear-cache[clearcache|cc] Clears composer's internal package cache
[clearcache|cc] Composer の内部パッケージ キャッシュをクリアします
completionDump the shell completion script
シェル完了スクリプトをダンプする
configSets config options
構成オプションを設定します
create-projectCreates new project from a package into given directory
パッケージから指定されたディレクトリに新しいプロジェクトを作成します
depends[why] Shows which packages cause the given package to be installed
[why] 指定されたパッケージがインストールされる原因となったパッケージを表示します
diagnoseDiagnoses the system to identify common errors
システムを診断して一般的なエラーを特定します
dump-autoload[dumpautoload] Dumps the autoloader
[dumpautoload] オートローダーをダンプします
execExecutes a vendored binary/script
ベンダーのバイナリ/スクリプトを実行します
fundDiscover how to help fund the maintenance of your dependencies
依存関係の維持に資金を提供する方法を見つける
globalAllows running commands in the global composer dir ($COMPOSER_HOME)
グローバルComposerディレクトリ ($COMPOSER_HOME) でのコマンドの実行を許可します。
helpDisplay help for a command
コマンドのヘルプを表示する
initCreates a basic composer.json file in current directory
現在のディレクトリに基本的なcomposer.jsonファイルを作成します
install[i] Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json
[i] 存在する場合は、composer.lock ファイルからプロジェクトの依存関係をインストールするか、composer.json にフォールバックします。
licensesShows information about licenses of dependencies
依存関係のライセンスに関する情報を表示します
listList commands
コマンドの一覧
outdatedShows a list of installed packages that have updates available, including their latest version
最新バージョンを含む、利用可能なアップデートがあるインストール済みパッケージのリストを表示します。
prohibits[why-not] Shows which packages prevent the given package from being installed
[why-not] 指定されたパッケージのインストールを妨げているパッケージを示します
reinstallUninstalls and reinstalls the given package names
指定されたパッケージ名をアンインストールして再インストールします
remove[rm] Removes a package from the require or require-dev
[rm] require または require-dev からパッケージを削除します。
require[r] Adds required packages to your composer.json and installs them
[r] 必要なパッケージをcomposer.jsonに追加してインストールします。
run-script[run] Runs the scripts defined in composer.json
[run]composer.json で定義されたスクリプトを実行します。
searchSearches for packages
パッケージの検索
self-update[selfupdate] Updates composer.phar to the latest version
[selfupdate]composer.pharを最新バージョンに更新します
show[info] Shows information about packages
[info] パッケージに関する情報を表示します
statusShows a list of locally modified packages
ローカルで変更されたパッケージのリストを表示します
suggestsShows package suggestions
パッケージの提案を表示します
update[u|upgrade] Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file
[u|upgrade] combos.json に従って依存関係を最新バージョンに更新し、composer.lock ファイルを更新します。
validateValidates a composer.json and composer.lock
composer.json と composer.lock を検証します。

関連記事

スポンサーリンク

Linuxでrarファイルを圧縮・解凍する方法(CentOS)

ホームページ製作・web系アプリ系の製作案件募集中です。

上に戻る