WindowsでVagrant + VirtualBox 環境構築

Vagrant / VirtualBox による仮想環境の構築メモです。

構成は、
・Centos 6.7
・Apache 2.2
・MariaDB 10.2
・PHP 7.1
です。

■ Vagrant インストール
こちらからVagrantをダウンロードします。
https://www.vagrantup.com/downloads.html

ダウンロードファイルをダブルクリックしてインストールします。
vagrant_2.0.1_x86_64.msi 

■ VirtualBox インストール
https://www.virtualbox.org/wiki/Downloads

ダウンロードファイルをダブルクリックしてインストールします。
VirtualBox-5.2.4-119785-Win.exe

■ VirtualBox に CentOS boxファイルを登録する
vagrant box add VM名 boxファイルURL
vagrant box add centos6-7 https://github.com/CommanderK5/packer-centos-template/releases/download/0.6.7/vagrant-centos-6.7.box

確認
vagrant box list
centos6-7 があればok。

■ Vagrantfileの作成
vagrant init box名 で生成します。

vagrant init centos6-7
カレントディレクトリにVagrantfileができます。

■ Vagrantfile編集

// Windowsから見られるIP指定
config.vm.network "private_network", ip: "192.168.33.10"

// GUIモードの設定をONにする(不要な場合は、以下全てコメントのままでok)
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = true
end

■ VM起動
vagrant up

vagrant halt
vagrant status
..

■ ssh
vagrant ssh
※centos6-7(Vagrantfileのある)ディレクトリから

■ EPELのリポジトリのインストール
# yum install epel-release
※#はrootユーザー

■ yumリポジトリにRemiを追加
※EPELのyumリポジトリが追加されている必要があります。

# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
又は
Remiのリポジトリ設定パッケージをダウンロード
$ wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
Remiのリポジトリのインストール
# rpm -Uvh remi-release-6.rpm

■ PHP7.1
インストールPHP確認
# rpm -qa | grep php

インストール
PHP7.1
# yum install --enablerepo=remi,remi-php71 php php-devel php-mbstring php-pdo php-gd php-xml php-mcrypt

MySQL追加の場合は、こちら。
# yum install --enablerepo=remi,remi-php71 php php-devel php-mbstring php-pdo php-gd php-xml php-mcrypt php-mysql

php.ini 編集
#vi /etc/php.ini

date.timezone = "Asia/Tokyo"

mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_input = UTF-8
mbstring.http_output = pass
mbstring.encoding_translation = On
mbstring.detect_order = auto
mbstring.substitute_charset = none

Composerをインストール
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

■ Apache
CentOS6.7の標準レポジトリからインストールできるのは2.2.15

# yum install httpd

# vi /etc/httpd/conf/httpd.conf

サービスの登録(OS起動時にApache起動)
# chkconfig httpd on
起動
# service httpd start
# service httpd restart
ステータス
# service httpd status

■ MariaDB
MariaDB yum リポジトリの追加

/etc/yum.repos.d/MariaDB.repo[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
enabled=1

yum で MariaDB をインストール

command$ sudo yum install MariaDB-server MariaDB-client

起動名は、mysql なのでした。

command$ rpm -ql MariaDB-server | grep init
/etc/init.d/mysql

サービス開始と登録。

command$ sudo service mysql start
$ sudo chkconfig mysql on

command$ mysql --version
mysql  Ver 15.1 Distrib 10.2.12-MariaDB, for Linux (x86_64) using readline 5.1

ログインしてみる!

command$ mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.2.12-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

■ phpMyAdmin

ダウンロードはこちら
https://www.phpmyadmin.net/
*現時点 Latest Version : 4.7.7

DocumentRootへ解凍・配置します。
/var/www/html/

解凍すると、ディレクトリは → phpMyAdmin-4.7.7-all-languages
長いので、phpMyAdminに変更。

ブラウザで確認します。
http://192.168.33.20/phpMyAdmin/

phpMyAdmin - エラー
mysqli 拡張がありません。PHP の設定をチェックしてみてください。 See our documentation for more information.

と怒られます。
PHPインストールでphp-mysql を入れていませんでした!

command$  rpm -qa | grep php
php-json-7.1.13-1.el6.remi.x86_64
php-gd-7.1.13-1.el6.remi.x86_64
php-xml-7.1.13-1.el6.remi.x86_64
php-devel-7.1.13-1.el6.remi.x86_64
php-pdo-7.1.13-1.el6.remi.x86_64
php-common-7.1.13-1.el6.remi.x86_64
php-cli-7.1.13-1.el6.remi.x86_64
php-mcrypt-7.1.13-1.el6.remi.x86_64
php-7.1.13-1.el6.remi.x86_64
php-mbstring-7.1.13-1.el6.remi.x86_64

mysqli をインストールして、Apacheを再起動します。

command# yum install --enablerepo=remi,remi-php71 php-mysql

■ その他
サービスの自動起動リスト
$ chkconfig --list

以上!

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です