pkgとphp composerを使ったphp markdownのインストール

はじめに

Windows XPからPC-BSDにOSを変えたので,php markdownを再インストールした.動作環境は以下の通り.

  • PC-BSD 10.3
  • pkg 1.7.2
  • php 5.6.22

php composerのインストール

phpを使ったインストール方法curlを使ったインストール方法があるが,バージョン管理の簡便さを考えてpkgを使うことにする.

pkgでの確認

pkgでインストールできる最新バージョンを確認する.

% pkg search php-composer
php-composer-1.0.0.a11_1       Dependency Manager for PHP

Composerの最新と同じなので,このままインストール.

pkgを使ったインストール

% sudo pkg install php-composer-1.0.0.a11_1

インストール場所

/usr/local/bin/composerができる.実際は/usr/local/bin/composer.pharへのシンボリックリンク.

composer.jsonの記述

php markdownをインストールディレクトリ(今回は${HOME}/test)にインストールするパッケージを記載したファイルcomposer.jsonを作る.記載内容は以下の通り.キー"require"とパッケージ名,バージョンの3個.バージョンは最新の1.6を指定.

{
  "require": {
    "michelf/php-markdown": ">=1.6"
  }
}

パッケージ名はPakagistで検索する.検索ボックス(「Search packages...」と書いてある)で「php markdown」を検索すると,「michelf/php-markdown」が出てくる.これがパッケージ名,バージョンも出ているので,それに合わせてcompoase.jsonに記載する.

インストール

pkgでインストールすると,composer.pharのシンボリックリンクが/usr/local/bin/composerにできる.コマンドラインからcomposer installと打てば実行できる./usr/local/bin/composerにシンボリックリンクがない場合はphp composer.phar installとphpにcomposer.pharを指定して動かす.

~/test% composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing michelf/php-markdown (1.6.0)
    Downloading: 100%         

Writing lock file
Generating autoload files
~/test% 

install成功.test/vendorディレクトリができ,その配下にmichelfサブディレクトリができる.

エラー

ちなみに,パッケージ名を間違えるとこんなエラーになる(正:michelf,誤:michef).メッセージを読むと「パッケージ名を打ち間違えてるよ」と書いてある.

~/test% composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package michef/php-markdown could not be found in any version, there may be a typo in the package name.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
~/test% 

参考サイト