LoginSignup
1
1

More than 5 years have passed since last update.

PHPのYAMLライブラリをhome brewでインストール

Last updated at Posted at 2016-05-22

概要

PHPでyamlを使いたいなと思ったのですが、標準ではyamlをパースするライブラリが入っていないみたいなので第4回 PHP編:言語別 YAML用ライブラリ徹底解説を参考にして、PHP用のYAMLライブラリを探してみると「PHPでYAMLパーサを使いたいなら,現在いちばんお勧めです。」と書いてあったのでhome brewでインストールした際の記録を書いてみました。

個人用のメモです。

環境

OS : OS X El capitan 10.11.4
PHP : 5.5

インストール手順

PHPのバージョンを確認 => PHP5.5がインストールされていることを確認

php -version
PHP 5.5.31 (cli) (built: Feb 20 2016 20:33:10)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies

yaml用パースライブラリを探すと複数のバージョン用のが見つかります。

brew search yaml
libyaml                                                                          yaml-cpp
homebrew/emacs/yaml-mode   homebrew/php/php53-yaml    homebrew/php/php54-yaml    homebrew/php/php55-yaml    homebrew/php/php56-yaml    homebrew/php/php70-yaml

PHP5.5用のphp_yamlをhome brewでインストールするがエラーになりました。

brew install php55-yaml
Error: No available formula with the name "php55-yaml"
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching taps...
This formula was found in a tap:
homebrew/php/php55-yaml
To install it, run:
  brew install homebrew/php/php55-yaml

コンソールに表示されている通りのコマンドを実行したらインストールは成功

brew install homebrew/php/php55-yaml

;途中長いので省略

To finish installing yaml for PHP 5.5:
  * /usr/local/etc/php/5.5/conf.d/ext-yaml.ini was created,
    do not forget to remove it upon extension removal.
  * Validate installation via one of the following methods:
  *
  * Using PHP from a webserver:
  * - Restart your webserver.
  * - Write a PHP page that calls "phpinfo();"
  * - Load it in a browser and look for the info on the yaml module.
  * - If you see it, you have been successful!
  *
  * Using PHP from the command line:
  * - Run `php -i "(command-line 'phpinfo()')"`
  * - Look for the info on the yaml module.
  * - If you see it, you have been successful!
==> Summary
  /usr/local/Cellar/php55-yaml/1.2.0: 2 files, 45.4K, built in 19 seconds

ファイルが作られていることを確認。上のメッセージには、拡張モジュールを削除した時はこれを削除するの忘れるなと書いてある。このファイルも自動で削除されないてことか?

ls -alF /usr/local/etc/php/5.5/conf.d/ext-yaml.ini
-rw-r--r--  1 hogetaro  admin  53  5 22 11:25 /usr/local/etc/php/5.5/conf.d/ext-yaml.ini

正常にインストールされたことをコマンドラインから確認

php -r 'phpinfo();'

:ずらずらっといろいろと表示された中にyamlの情報を発見
yaml

LibYAML Support => enabled
Module Version => 1.2.0
LibYAML Version => 0.1.6

Directive => Local Value => Master Value
yaml.decode_binary => 0 => 0
yaml.decode_php => 1 => 1
yaml.decode_timestamp => 0 => 0
yaml.output_canonical => 0 => 0
yaml.output_indent => 2 => 2
yaml.output_width => 80 => 80

ymfony vs PECL: YAMLのパースベンチマークとってみたの記事を参考にしてpecl yamlだけベンチマークをとってみました。

php test02.php
yaml_parse(): 0.090523958206177

参考にしたサイト

今回home brewでphp_yamlをインストールにする際に参考にさせて頂いたサイトです。ありがとうございました。

OX X EL Captianで複数のバージョンのPHPを使う方法
OS X 10.11 El Capitan Apache Setup: Multiple PHP Versions
OS X 10.11 El Capitan Apache Setup: MySQL, APC & More...

因みに2番目のドキュメントに出てくるsphpは上のドキュメント内に出てきたPHPのバージョンを変更するスクリプトのことらしい。

1
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1