refrainingの耐え忍ぶ日々

Webエンジニアの雑記帳です。内容は主にプログラミングに関する事です。

Docker for Mac インストール手順

基本的にはオフィシャルサイトの手順通りに実施すればOKです。

と思い実施したところ・・・Fatal Error発生!
f:id:refraining:20160820084532p:plain

オフィシャルサイトに記載されているシステム要件は満たしているはずだけど。。。

System Requirements: Docker for Mac will launch only if all these requirements are met.
Mac must be a 2010 or newer model, with Intel’s hardware support for memory management unit (MMU) virtualization; i.e., Extended Page Tables (EPT)
OS X 10.10.3 Yosemite or newer
At least 4GB of RAM
VirtualBox prior to version 4.3.30 must NOT be installed (it is incompatible with Docker for Mac)

調査の結果、どうやら自分のMacがHypervisor frameworkをサポートしてないことが原因と判明。
以下のコマンドでその確認が可能です。

$ sysctl kern.hv_support
kern.hv_support: 0

オフィシャルサイトには

If your Mac supports the Hypervisor Framework, the command will print kern.hv_support: 1.
If not, the command will print kern.hv_support: 0.

と記載されているので、やはり自分のMacはHypervisor frameworkをサポートしていませんでした。

なので、Docker for MacはあきらめてDocker Toolboxをインストールします!
手順通りにインストールを実行したら、Docker Quickstart Terminalが起動したことを確認しました!

OS X El CapitanにAtomでphpのデバッグ環境を構築

OS X El CapitanにAtomphpデバッグを可能にする環境構築手順を紹介します。

XDebugをインストール

Xdebug: Downloadsからインストール済みのPHPのバージョンに適用可能なバージョンのXDebugをダウンロードします。
自分の環境はPHP Version 5.5.34をインストール済みの為、Xdebug 2.4.0をダウンロードしました。
ターミナルを起動し、ダウンロードしたファイルのディレクトリに移動して以下のコマンドを実行します。

$ tar xvfz xdebug-2.4.0.tgz
$ cd xdebug-2.4.0
$ phpize
Configuring for:
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

autoconfが見つからないというエラーが発生しました。
brewでautoconfをインストールして、エラーメッセージに表示されているように環境変数を設定します。

$ brew install autoconf
$ export PHP_AUTOCONF=/usr/local/Cellar/autoconf/2.69/bin/autoconf

再度phpizeコマンドを実行します。

$ phpize
Configuring for:
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212
Cannot find autoheader. Please check your autoconf installation and the
$PHP_AUTOHEADER environment variable. Then, rerun this script.

またエラーが発生しました。やれやれだぜ。。。
autoheaderは既に/usr/local/Cellar/autoconf/2.69/bin/autoheaderにインストール済みなので、autoconfと同様に、環境変数を設定します。

$ export PHP_AUTOHEADER=/usr/local/Cellar/autoconf/2.69/bin/autoheader

再度、phpizeを実行すると今度はエラーが発生せず、正常終了しました!

次に以下のコマンドを実行して、XDebugコンパイルします。

$ ./configure --enable-xdebug
$ make
$ make install

同じディレクトリのmodulesディレクトリ以下に、xdebug.soが存在することを確認します。

以下のコマンドを実行して、xdebug.soをコピーします。

$ sudo cp modules/xdebug.so /usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so

次にphp.iniを編集して、下記の内容を追加します。

$ vi /etc/php.ini
zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true

apacheを再起動します。

$ sudo apachectl graceful

Atomphp-debug packageをインストール

Atomを開いて設定画面を開きます。
Settings > Installを選択して、サーチボックスに「php-debug」を入力して、[Packages]ボタンをクリックし、php-debugの[Install]ボタンをクリックします。
f:id:refraining:20160724231449p:plain
Atomを再起動して、以下のようにphpファイルの行番号の部分で右クリックして、PHP-Debug > Toggle Breakpointでブレークポイントを設定することが可能になります。