WindowsでVagrant + VirtualBox + LAMP環境構築(Cake PHP)その1

仕事でCakePHPを用いたLAMP環境が必要になったので、環境構築してみる。

今回構築した環境の各バージョンです。

まずは仮想マシンLinux環境をVagrantを使って構築していきます。

VagrantVirtualBoxのインストールは割愛
それぞれ公式からダウンロードしてインストール。 特に設定は変更せず次へすすめていく。

ここではcentosで作成します。 その他boxは下記から探せます。 https://app.vagrantup.com/boxes/search

仮想マシン構築&起動

コマンドプロンプト入力にて、任意のディレクトリに移動し、 今回の環境構築用にフォルダを作成 以降はこのフォルダ内でコマンド打っていきます。

$ mkdir cake
$ cd cake/

box追加

$ vagrant box add cnetos/7
==> box: Loading metadata for box 'centos/7'
    box: URL: https://vagrantcloud.com/centos/7
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.

1) hyperv
2) libvirt
3) virtualbox
4) vmware_desktop

Enter your choice: 

途中入力を促されますが、VirtualBoxを使うので

3) virtualbox を選択

しばらく待つとboxが作成されます。

作成したboxは下記のコマンドで確認できます。

$ vagrant box list
centos/7          (virtualbox, 1905.1)

Vagrantfile作成

$ vagrant init centos/7
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の編集

# config.vm.network "private_network", ip: "192.168.33.10"

これで仮想マシン側が受け付けるIPを192.168.33.10に指定します。

  • プロキシ設定

プロキシ環境の場合は、別途プロキシ接続用のプラグインのインストールが必要です。 コマンドプロンプトで下記のコマンドを実行して、インストールします。

$ vagrant plugin install vagrant-proxyconf

インストールが出来ない場合は、コマンドプロンプト自体にプロキシ設定が必要なので、 コマンド実行前に環境変数を設定します。 下記はgit-bashでの実行方法

export HTTP_PROXY=http://proxysrv:port/
export HTTPS_PROXY=${HTTP_PROXY}

コマンドプロンプトの場合

SET HTTP_PROXY=http://proxysrv:port
SET HTTPS_PROXY=${HTTP_PROXY}

プラグインのインストールが終わったら、Vagrantfileに下記を追加します。

  if Vagrant.has_plugin?("vagrant-proxyconf")
    config.proxy.http     = "ホスト名:ポート番号"
    config.proxy.https    = "ホスト名:ポート番号"
    config.proxy.no_proxy = "localhost, 127.0.0.1"
  end

仮想マシンの起動

$ vagrant up

仮想マシンにログイン

$ vagrant ssh

OSを確認

[vagrant@localhost ~]$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

次は仮想マシン内にApacheMySQLPHPのインストールを行っていきます。

katutoki.hatenablog.com