LoginSignup
0
2

More than 5 years have passed since last update.

Vagrant CentOS7の環境にPHP7.0 MySQL 5.7 Apache 2.4でDrupal7を構築する

Last updated at Posted at 2016-10-30

vagrantでcentos7x64のパッケージを追加する。

$vagrant box add CentOS7.0 https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box

$vagrant init CentOS7.0

vagrantfileが作成される。

アクセスするIPアドレス設定

vagrantfileの以下の部分のコメントアウトを外す。

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

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

CentOS内の環境設定

centOSを起動
$vagrant up

CentOSに入る
vagrant ssh

入れる環境
* PHP7.0
* MySQL 5.7
* apache 2.4

一応yumをupdateしときましょう。
$sudo yum -y update

ファイヤーウォールの設定

default-zoneをdmzとする
#sudo firewall-cmd --set-default-zone=dmz
Apacheの80番ポート開放
#sudo firewall-cmd --zone=dmz --add-port=80/tcp

Remiリポジトリの追加

Remiリポジトリ追加のためにEPELリポジトリ追加
EPELリポジトリ
$sudo yum install -y epel-release

Remiリポジトリ

sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

php7
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

MySQL5.7
sudo rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

Apacheのインストール

$sudo yum install -y httpd httpd-devel

MySQLの設定

MySQLのインストール
sudo yum install -y mysql-community-server

MySQLを起動
sudo systemctl start mysqld.service

初回起動時にパスワードが生成されるので初期パスワードを確認する
sudo cat /var/log/mysqld.log | grep 'temporary password'

パスワードをリセットする。
$mysql_secure_installation

パスワードを求められるので先ほど確認したパスワードを入れる。
Enter password for user root: (確認したパスワードを入れてEnter)
新しいパスワードを求められる。
New password:(パスワードを考え入力しEnter)
再入力
Re-enter new password: (パスワードを再入力)
Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y

New password: (新パスワード)

Re-enter new password: (新パスワード)

匿名ユーザーアカウントを削除。
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

ローカルホスト以外からアクセス可能な root アカウントを削除。
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

test データベースの削除
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
リロード
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

MySQLにログインできるか確認
mysql -uroot -p設定したパスワード
Drupal用のデータベースを作成
mysql> CREATE DATABASE drupal;

データベースを抜ける
mysql> exit

MySQLの自動起動設定
$ sudo systemctl enable mysqld.service

phpのインストール

sudo yum install -y --enablerepo=webtatic-testing php70w php70w-opcache php70w-mbstring php70w-mysql php70w-dom php70w-gd php70w-devel php70w-pdo

/etc/httpd/conf/httpd.confの設定を変更
<Directory /var/www/html/>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>

Apache設定

Apache自動起動
sudo systemctl enable httpd.service
Apacheの起動
sudo systemctl start httpd.service

vagrantの共有フォルダの設定

sudo rm -rf /var/www/html
sudo ln -fs /vagrant /var/www/html

apachに権限を付与 vagrantfile に以下を追記

config.vm.synced_folder "./", "/vagrant",
:owner => "apache",
:group => "apache",
:mount_options => ["dmode=775,fmode=775"]

vagrant reload

Drupal7をダウンロードをダウンロードして展開

cd /vagrant
wget https://ftp.drupal.org/files/projects/drupal-7.51.tar.gz
sudo tar -zxvf drupal-7.51.tar.gz
cd ./drupal-7.51/sites/default/
sudo mkdir files
sudo cp -pi default.settings.php settings.php
chmod 777 files/
chmod 777 settings.php

https://localize.drupal.org/download
からインストール時の日本語へのtranslasionファイルをダウンロード
japaneseのdrupal-7.51.ja.po
ダウンロード先はdrupal-7.51/profiles/standard/translations

ブラウザから以下にアクセス
http://192.168.33.10/drupal-7.51

Select an installation profile

standard

Choose language

Japanese (日本語)

データベースの設定

MySQL
データベース名
自分で決めたデータベース名(本記事ではdrupal)
データベースのユーザー名
今回は作業ユーザーをつくなかったためroot
データベースのパスワード
データベースインストール時に設定したパスワード

サイト情報

適宜入力

参考にしたサイト

http://qiita.com/ksugawara61/items/336ffab798e05cae4afc
http://qiita.com/m_46/items/2acd238253e9fb1a45fd
http://blog.buddying.jp/tips/2015-06-03/184/

0
2
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
0
2