LoginSignup
4
5

More than 5 years have passed since last update.

ゼロからphp7環境構築 - 0.事前準備

Last updated at Posted at 2016-11-25

次回: ゼロからphp7環境構築 - 1.DBサーバー設定


概要

  • centOS7
  • Apache
  • php7
  • MariaDB

の環境を、vagrantを使用して、ゼロから作っていきます
せっかくなので、下記のようなことをしてみたいと思います

  • appサーバーとdbサーバーを分ける
  • git commitにHookをかけて静的コードチェック(phpcs, phpmd, phpcpd)
  • gitLabサーバーを立てて、gitHubフローでソース管理
  • nginxでリバースプロキシ立ててappサーバー二台構成
  • dbサーバー二台構成(master/slave)でレプリケーション

まずはboxを作るところから

もくじ

  • Vagrant, VirtualBox インストール
  • 作業フォルダ作成
  • vagrant init
  • Vagrantfile 編集
  • vagrant up
  • ssh接続
  • yum update
  • centOSの設定
  • git, vim インストール
  • box作成・追加

Vagrant, VirtualBox インストール

Vagrant公式サイト

1.8.6 使用

VirtualBox公式サイト

5.1.8 r111374 (Qt5.5.1) 使用

作業フォルダ作成

C:\HashiCorp\Vagrant 以下に作業フォルダを作成します
(windowsでの作業には PowerShell を使用しています)

cd C:\HashiCorp\Vagrant
mkdir work
mkdir work\testProject
mkdir work\testProject\appServer

vagrant init

cd work\testProject\appServer
vagrant init bento/centos-7.2

下記のメッセージが表示され、bento/centos-7.2 の指定されたVagrantfile(vagrantの設定ファイル)が作成されます

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.

ls
-a---        2016/11/18     10:59       3091 Vagrantfile

Vagrantfile 編集

変更前

# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"

変更後

# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.33.11"

vagrant up

vagrant up

初回はBOXをインストールするため、時間がかかります(5分くらいかかった)

通常は事前にdown load, vagrant box add が必要ですが、特定のBox名を指定することでhashicorpが提供するboxの提供サイトから自動で取得します
Atlas - These boxes are built using templates from the Bento project -

ステータスの確認

vagrant status

default running (virtualbox) と表示されればOK

ssh接続

macなどssh接続できるターミナルを使用している場合は、 vagrant ssh で接続できます
windowの場合は、Tera Term, Putty などのssh可能なターミナルをインストールしてください
先ほど設定した 192.168.33.11 を指定すれば接続できます(ID PassWordは vagrant)

yum update

ssh接続先にて。時間がかかります(10分くらいかかった)

sudo yum update

centOSの設定

fireWall停止, 自動起動解除

sudo systemctl stop firewalld
sudo systemctl disable firewalld

git, vim インストール

sudo yum -y install git
sudo yum -y install vim
sudo yum -y install zip unzip

最適化

sudo yum clean all
sudo dd if=/dev/zero of=/EMPTY bs=1M
sudo rm -f /EMPTY

box作成・追加

pc側で

vagrant halt
vagrant package
vagrant box add --name centos72 package.box
vagrant box list

centos72 が追加されていることを確認


次回: ゼロからphp7環境構築 - 1.DBサーバー設定

4
5
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
4
5