LoginSignup
3
3

More than 5 years have passed since last update.

Vagrant+VirtualBoxで作成した仮想マシンにPHPライブラリテスト用環境を構築する【1】

Last updated at Posted at 2017-02-09

Vagrant+VirtualBoxで作成した仮想マシンにPHPライブラリテスト用環境を構築する【1】 ←イマココ
Vagrant+VirtualBoxで作成した仮想マシンにPHPライブラリテスト用環境を構築する【2】
Vagrant+VirtualBoxで作成した仮想マシンにPHPライブラリテスト用環境を構築する【3】
Vagrant+VirtualBoxで構築した仮想マシンをBox化して復元する

はじめに

PHPの色々なライブラリが入ったプロジェクトのテストを本番に近い環境で行いたい。
なのでVagrant+VirtualBoxで作成した仮想マシンにPHPライブラリテスト用環境を構築する。

実施環境

項目 詳細
MacOS Sierra
Vagrant 1.9.1
VirtualBox 5.1.14

目標仮想マシン環境

LAMP

項目 詳細
Linux CentOS6.6
Apache 2.4.6
MySQL 5.7
PHP 5.6
FW Codeigniter3

今回テストしたいライブラリはImage_Barcode2

事前準備

以下をインストールする。

仮想マシンの準備

Boxの取得

Boxとは仮想マシンのテンプレート。
以下のコマンドで取得できる。

$ vagrant box add {title} {url}

Vagrantbox.esより目的にあったイメージを選択し、Boxを取得する。
今回は「CentOS 6.6 x64」のBoxを取得するので以下のようになる。(titleはなんでもいい)

$ vagrant box add CentOS6 https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.0.0/centos-6.6-x86_64.box

完了後、以下のコマンドで取得できているか確認ができる。

$ vagrant box list
CentOS6     (virtualbox, 0)

入ってる入ってる。

【追記】
現在はVagrantが公式でBoxを用意してくれているようなので、以下の記事を参考した方がいい!
Vagrantの正しいはじめ方

仮想マシンの初期化

仮想マシンごとにディレクトリが必要なので、作成して移動。

$ mkdir libTestCentOSVM
$ cd libTestCentOSVM

初期化

libTestCentOSVM $ vagrant init CentOS6
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.

成功したら、Vagrantfileが作成される。

libTestCentOSVM $ ls
Vagrantfile

仮想マシンの起動

libTestCentOSVM $vagrant up

完了すると、VirtualBox上でも起動を確認できる。
スクリーンショット 2017-02-09 10.58.16.png

※停止・再起動・削除などはググってください。

仮想マシンに接続

libTestCentOSVM $vagrant ssh
Last login: Thu Jul 16 08:48:31 2015 from 10.0.2.2
Welcome to your Vagrant-built virtual machine.
[vagrant@localhost ~]$ 

できましたー:beers:




Vagrantの設定はこれで終わりー:neutral_face:
次はサーバー側の環境構築
長くなるので別記事へ続く!!
Vagrant+VirtualBoxで作成した仮想マシンにPHPライブラリテスト用環境を構築する【2】

3
3
0

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
3
3