LoginSignup
1
1

More than 5 years have passed since last update.

Vagrantセットアップ

Last updated at Posted at 2016-08-03

1. サーバーを構築したいディレクトリへ移動し、利用するBOXで初期化

vagrant init <BOX名>

Vagrantfileを編集

ブラウザからアクセスできるようにする
vagrant-hostsupdaterのようなローカルマシンのhostsファイルを自動で書き換えてくれるプラグインも忘れずにインストールしておく

config.vm.network "private_network", ip: "192.168.33.10"
config.vm.hostname = "local.vagrant"

2. Vagrant起動

vagrant up

3. CentOSの諸々の設定を行う

  • シンボリックリンクで同期
  • Apacheのインストールと設定
  • PHPのインストールと設定

仮想マシンとホストマシンをシンボリックリンクで同期

Vagrant sshでログインする。

sudo rm -r var/www/html
sudo ln -s /vagrant /var/www/html

Apacheのインストールと設定

vagrant sshで仮想サーバーにログインし、ApacheとPHPをインストールします。

sudo yum -y install httpd
sudo service httpd start

# ファイアーウォールをOFFにして、再起動してもOFFのままにする
sudo service iptables stop
sudo chkconfig iptables off

httpd.confの設定
 静的ファイル群の更新が反映されないので、sendfile機能をOFFにする。

EnableSendfile off

sudo service httpd restart

PHPのインストールと設定

sudo yum -y install php

httpd.confに追記

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

sudo service httpd restart

VagrantへiPhoneなど外部デバイスからアクセスする

同じWi-Fiに接続していることが前提。
 Vagrantfileを編集し以下をコメントアウト。vagrant reloadすると、ネットワークの接続設定をどれにするか聞かれるので、WI-Fiを選択。

config.vm.network :public_network

その後、Vagrant sshして、仮想サーバーにログインし、ifconfigで、IPを確認し、Iphoneなどからアクセスする。

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