Home > アーカイブ > 2013-07

2013-07

Vagrant を使うなら、VirtualBox 4.2.16 以降で

この記事の所要時間: 633

VirtualBox 4.2.14 + Vagrant 1.2.2 の組み合わせで、正常に動作しなかった問題が、VirtualBox 4.2.16 で解決されたようです。

VirtualBox 4.2.14 + Vagrant 1.2.2 の組み合わせで、一部の環境にて vagrant up ができないという現象がありました。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'precise32'...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["import", "/Users/hans/.vagrant.d/boxes/precise32/virtualbox/box.ovf"]

Stderr: 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Interpreting /Users/hans/.vagrant.d/boxes/precise32/virtualbox/box.ovf...
OK.
0%...
Progress object failure: NS_ERROR_CALL_FAILED

https://github.com/mitchellh/vagrant/issues/1847

Vagrant の github サイトでもこの問題に関する issue が上がっていましたが、いずれも VirtualBox 4.2.16 で解決したようです。

手元の環境をVirtualBox 4.2.8 から 4.2.16 にアップグレードしたところ、Vagrant 1.2.2 との組み合わせで正常に動作しました。(sahara プラグインもちゃんと動きました:D)

  • Mac OS X 10.7.5
  • Vagrant 1.2.2
  • VirtualBox 4.2.16
$ vagrant -v
Vagrant version 1.2.2
$ VirtualBox -h
Oracle VM VirtualBox Manager 4.2.16
(C) 2005-2013 Oracle Corporation
All rights reserved.
(snip)

$ vagrant init precise32 http://files.vagrantup.com/precise32.box
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Box 'precise32' was not found. Fetching box from specified URL for
the provider 'virtualbox'. Note that if the URL does not have
a box for this provider, you should interrupt Vagrant now and add
the box yourself. Otherwise Vagrant will attempt to download the
full box prior to discovering this error.
Downloading or copying the box...
Extracting box...te: 1905k/s, Estimated time remaining: --:--:--)
Successfully added box 'precise32' with provider 'virtualbox'!
[default] Importing base box 'precise32'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Fixed port collision for 22 => 2222. Now on port 2201.
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2201 (adapter 1)
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Configuring and enabling network interfaces...
[default] Mounting shared folders...
[default] -- /vagrant

$  vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)

 * Documentation:  https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 14 06:22:31 2012 from 10.0.2.2
vagrant@precise32:~$
  • コメント (Close): 0
  • トラックバック (Close): 0

phpenv + php-build 環境を Vagrant で構築する

この記事の所要時間: 319

PHP5.5 リリースにより、再び盛り上がってきた phpenv + php-build 環境を Vagrant で作ってみました。

vagrant

CentOS6.4 + phpenv + php-build + nginx という構成になっています。

nginx + phpenv + php-build の環境構築については hnw さんの下記エントリがとても参考になりました。

php-buildで複数バージョンのPHP-FPMを用意する – hnwの日記

インストール

https://github.com/shin1x1/vagrant-phpenv-phpbuild

github へ Vagrantfile + Chef レシピファイルをアップしています。こちらの README に書いたとおりですが、手順としては以下になります。

  1. VirtualBox インストール
  2. Vagrant インストール
  3. git clone
  4. vagrant up

1 / 2 はインストール済であれば不要です。(なお VirtualBox 4.2.14(2013/07/01 時点の最新版) は、Vagrant との組み合わせで問題が発生する場合があるので、現時点では 4.2.12や4.2.8など旧バージョンのインストールをお勧めします。)

4 は、box ファイルのダウンロードや PHP のビルドでかなり時間がかかる場合があります。コマンドを実行した後はのんびりお待ちを。

SSH でアクセス

vagrant ssh でログインすると、phpenv コマンドが利用できます。

php コマンドで実行される PHP バージョンを変更したり、さらに別バージョンの PHP をインストールすることが可能です。

HTTP でアクセス

Vagrant で起動した仮想サーバには IP アドレスに 192.168.33.14 を付与しています。
稼働サーバでは nginx が動作しており、ポート毎に各バージョンの php-fpm が割り当てられています。

  • http://192.168.33.14:8053/ -> PHP5.3
  • http://192.168.33.14:8054/ -> PHP5.4
  • http://192.168.33.14:8055/ -> PHP5.5

ドキュメントルート

仮想サーバ内の /public_html ディレクトリが nginx のドキュメントルートになっています。

このディレクトリはホスト側の public_html ディレクトリをシェアしているので、このディレクトリに PHP ファイルを設置すれば、仮想サーバの nginx+php-fpm で実行することができます。

例えば、下記のように echo.php をホスト側の public_html ディレクトリ以下に作成すると、http://192.168.33.14:8053/echo.php で実行することができます。

$ ls .
README.md   Vagrantfile cookbooks   public_html
$ echo "<?php echo PHP_VERSION;" > public_html/echo.php

Vagrantfile をカスタム

Vagrantfile をカスタムすることで、インストールする PHP バージョンを変更したり、configure オプションを追加することが可能です。
詳しくは README にて。

参考

  • コメント (Close): 0
  • トラックバック (Close): 0

Home > アーカイブ > 2013-07

検索
フィード
メタ情報

Return to page top