LoginSignup
7
8

More than 5 years have passed since last update.

vagrant+virtualboxでapache+php開発環境構築

Last updated at Posted at 2015-01-15

構築の流れをメモします。
vagrantとvirtualboxのインストールは割愛

webサーバにapache, プログラミグ言語がphpという環境を
centos6.5上に作成します

1).Boxの取得

作業ディレクトリを用意

$ mkdir vagrant
$ cd vagrant

Vagrantbox.es から好みのOSを選択して、boxに追加。今回は、「CentOS 6.5 x86_64」にしました。

$ vagrant box add centos65x86_64 https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box

...
Successfully added box 'centos65x86_64' with provider 'virtualbox'!

boxの確認。先ほどaddしたものが追加されている。

$ vagrant box list
centos65x86_64 (virtualbox)

2).vagrantfileの作成

以下コマンドで初期化

$ mkdir centos65x86_64
$ cd centos65x86_64
$ vagrant init centos65x86_64

実行後「Vagrantfile」が作成される。ただ今回は、何も修正しないで利用します。

3).vmの作成

以下コマンドで、VMを作成する

$ vagrant up

コマンド終了後、確認をする

$ vagrant status

4).vmにログイン

sshによりログイン

$ vagrant ssh
$ cat /etc/redhat-release 
CentOS release 6.5 (Final)

5).apache+phpのインストール

まずは、yum update

$ sudo yum update

続いて、apache+phpを。

$ sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

$ sudo yum install --enablerepo=remi --enablerepo=remi-php55 php

phpのバージョン確認

$ php -v
PHP 5.5.20 (cli) (built: Dec 17 2014 15:09:12)

apache起動。iptablesは無効にしておきます。

$ sudo service httpd start
$ sudo chkconfig httpd on

$ sudo service iptables stop
$ sudo chkconfig iptables off

6).vagrantfileの設定変更

ホストからvm内のapacheにアクセスできるように、Vagrantfileの以下の部分を修正する

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

設定変更を反映

$ vagrant reload

IPアドレス指定でブラウザからアクセス。
vm内でアクセスログを監視して確認

$ sudo tail -f /var/log/httpd/access_log

apacheのテストページが表示されればOK

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