月別アーカイブ: 2016年2月

VirtualBox5.0.14のCentOS6.7にWordPress4.2.2をインストールする手順

VirtualBox上にCentOS6.7を構築し、WordPress4.2.2をインストールしました。
CentOS6.6でインストールした手順と同じです。

CentOS6.7のインストール

仮想マシンを作成します。
「CentOS67」

インストーラーの起動します。
CentOS-6.7-x86_64-minimal.isoをドライブに設定し、起動します。

ホスト名:centos67

205個のパッケージをインストールします。約2分で終了しました。
再起動します。

順番が異なりますが、ホストOSからログインします。
最初からTeraTermでログインしたほうが、コピペしやすいので楽でした。
IP(192.168.56.101)でログインして、作業しました。

パッケージのインストール

以下をコピペします。

yum -y update
reboot
yum -y groupinstall "Base"
yum -y groupinstall "Development tools"
yum -y groupinstall "Japanese Support"
reboot

時間は10分ぐらいかかりました。

不要なサービスの停止

以下をコピペします。

chkconfig abrt-ccpp off
chkconfig abrt-oops off
chkconfig abrtd off
chkconfig acpid off
chkconfig atd off
chkconfig auditd off
chkconfig blk-availability off
chkconfig cpuspeed off
chkconfig haldaemon off
chkconfig ip6tables off
chkconfig iptables off
chkconfig irqbalance off
chkconfig iscsi off
chkconfig iscsid off
chkconfig lvm2-monitor off
chkconfig mdmonitor off
chkconfig messagebus off
chkconfig netfs off
chkconfig sysstat off
chkconfig udev-post off

vimの設定

先にvimrcを作成。

vi ~/.vimrc

以下の値を貼り付けて保存します。

set nocompatible
set fileformats=unix,dos,mac

set history=100
set ignorecase
set smartcase
set wrapscan
set incsearch
set title
set number
set laststatus=2
set statusline=%F%m%r%h%w\%=[TYPE=%Y]\[FORMAT=%{&ff}]\[文字コード=%{&fileencoding}]\[ASCII=\%03.3b]\ [HEX=\%02.2B]\[%04l行,%04v桁][%p%%]\ [LEN=%L]
 
if &encoding !=# 'utf-8'
  set encoding=japan
  set fileencoding=japan
endif
if has('iconv')
  let s:enc_euc = 'euc-jp'
  let s:enc_jis = 'iso-2022-jp'
  if iconv("\x87\x64\x87\x6a", 'cp932', 'eucjp-ms') ==# "\xad\xc5\xad\xcb"
	let s:enc_euc = 'eucjp-ms'
	let s:enc_jis = 'iso-2022-jp-3'
  elseif iconv("\x87\x64\x87\x6a", 'cp932', 'euc-jisx0213') ==# "\xad\xc5\xad\xcb"
	let s:enc_euc = 'euc-jisx0213'
	let s:enc_jis = 'iso-2022-jp-3'
  endif
  if &encoding ==# 'utf-8'
	let s:fileencodings_default = &fileencodings
	let &fileencodings = s:enc_jis .','. s:enc_euc .',cp932'
	let &fileencodings = &fileencodings .','. s:fileencodings_default
	unlet s:fileencodings_default
  else
	let &fileencodings = &fileencodings .','. s:enc_jis
	set fileencodings+=utf-8,ucs-2le,ucs-2
	if &encoding =~# '^\(euc-jp\|euc-jisx0213\|eucjp-ms\)$'
  	set fileencodings+=cp932
  	set fileencodings-=euc-jp
  	set fileencodings-=euc-jisx0213
  	set fileencodings-=eucjp-ms
  	let &encoding = s:enc_euc
  	let &fileencoding = s:enc_euc
    else
  	let &fileencodings = &fileencodings .','. s:enc_euc
	endif
  endif
  unlet s:enc_euc
  unlet s:enc_jis
endif
if has('autocmd')
  function! AU_ReCheck_FENC()
	if &fileencoding =~# 'iso-2022-jp' && search("[^\x01-\x7e]", 'n') == 0
  	let &fileencoding=&encoding
	endif
  endfunction
  autocmd BufReadPost * call AU_ReCheck_FENC()
endif
set fileformats=unix,dos,mac
if exists('&ambiwidth')
  set ambiwidth=double
endif

viコマンドを実行時にvimが起動するように設定します。

vi /etc/bashrc
alias vi='vim'

時刻同期の設定

OSの時刻が自動で同期されるようにntpの設定をします。
元の設定ファイルをバックアップし、新規に設定ファイルを作成します。

mv /etc/ntp.conf /etc/ntp.conf.org
vi /etc/ntp.conf
driftfile /var/lib/ntp/drift
server ntp1.jst.mfeed.ad.jp
server ntp2.jst.mfeed.ad.jp
server ntp3.jst.mfeed.ad.jp

サービスを起動して、自動起動を登録します。ntpqコマンドで同期確認をします。

/etc/rc.d/init.d/ntpd start
chkconfig ntpd on
ntpq -p

SELinux無効化にして再起動

vi /etc/sysconfig/selinux
SELINUX=disabled ←enforcingを変更!

保存後、rebootで再起動します。

Guest Additionsのインストール

「デバイス」→「Guest Additions のCDイメージを挿入」をクリックし、マウントして、スクリプトを実行します。

mkdir /mnt/cdrom
mount -r /dev/cdrom /mnt/cdrom
cd /mnt/cdrom
sh ./VBoxLinuxAdditions.run

インストールが完了しました。

共有フォルダの設定

VirtualBoxの設定で、C:\_VirtualBox\Shareフォルダ(←ホストOSからみた共有フォルダ)を作成して、共有します。
7-centos-3

作成後、ゲストOSを再起動します。
ゲストOSからは、/media/sf_Share/が共有フォルダになります。

ls /media/sf_Share/

vsftpdのインストール

yumコマンドでインストールし、サービスを起動、サービスの自動起動をONにします。

yum -y install vsftpd
service vsftpd start
chkconfig vsftpd on

vsftpdの設定

デフォルトではrootユーザーはFTP接続ができません。
/etc/vsftpd/user_listと/etc/vsftpd/ftpusersのファイルのrootを削除すれば接続できます。

vi /etc/vsftpd/user_list
vi /etc/vsftpd/ftpusers
service vsftpd restart

epelリポジトリの導入

yumコマンドでインストールし、デフォルトで利用しないように設定ファイルを編集します。

yum -y install epel-release
vi /etc/yum.repos.d/epel.repo

6行目をenabled=0にします。

[epel]
 name=Extra Packages for Enterprise Linux 6 - $basearch
 #baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
 mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
 failovermethod=priority
 enabled=0 ←1から変更
 gpgcheck=1
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6</pre>

remiリポジトリの導入

wgetコマンドでrpmを取得し、rpmコマンドでインストールします。
デフォルトで利用しない設定になっています。

wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6.rpm

PHPのインストール


#5.5.32をインストール
yum install -y --enablerepo=remi --enablerepo=remi-php55  php php-devel php-mysql php-mbstring php-gd

httpd -v
#→ 2.2.15のバージョン

MySQLのインストール

#5.5.48をインストール
yum install -y --enablerepo=remi mysql-server

PHP、httpdの設定

vi /etc/php.ini

PHPの設定ファイル/etc/php.iniを編集します。

366行目
expose_php = On
↓
expose_php = Off

452行目
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
↓
error_reporting = E_ALL

469行目
display_errors = Off
↓
display_errors = On

575行目
;error_log = php_errors.log
↓
error_log = /var/log/php.log

873行目
;date.timezone =
↓
date.timezone = Asia/Tokyo

1630行目コメント削除
;mbstring.language = Japanese
↓
mbstring.language = Japanese

1636行目コメント削除
;mstring.internal_encodinf = UTF8
↓
mstring.internal_encodinf = UTF8

1640行目追加
;mbstring.http_input = UTF-8
↓
mbstring.http_input = auto

1658行目コメント削除
;mbstring.detect_order = auto
↓
mbstring.detect_order = auto

httpdの設定ファイル/etc/httpd/conf/httpd.confを編集します。

vi /etc/httpd/conf/httpd.conf
338行目 .htaccessを有効にする
    AllowOverride All

編集後、httpdを起動し、サービスの自動起動をONにします。

service httpd start
chkconfig httpd on

MySQLの設定

vi /etc/my.cnf

MySQLの設定ファイル/etc/my.cnfを編集します。

[mysqld]
datadir=/var/lib/mysql
↓変更 (2行目)
datadir=/home/mysql

↓追記 (29,30行目)
skip-character-set-client-handshake
character-set-server=utf8

↓最終行に下記を記入
[mysql]
default-character-set=utf8

編集後、データディレクトリを作成し、mysqldを起動し、サービスの自動起動をONにします。

mkdir /home/mysql
chown -R mysql:mysql /home/mysql
/etc/rc.d/init.d/mysqld start
chkconfig mysqld on

rootユーザーのパスワード設定、不要なデータの削除を行います。

#■ログイン
mysql -u root
#■MySQLのrootパスワードを設定
mysql> SET PASSWORD FOR root@localhost=password('root');
#■ユーザー名がない空ユーザーを削除
mysql> SELECT user,host FROM mysql.user; 
mysql> DELETE FROM mysql.user WHERE user='';
mysql> SELECT user,host FROM mysql.user; 
#■不要なデータベースを削除
mysql> SHOW DATABASES;
mysql> DROP DATABASE test;
mysql> SHOW DATABASES;
mysql> exit
#■サービスを再起動
service mysqld restart
#■次回からのログイン
mysql -u root -p
Enter password: root
#■文字コードを確認。
mysql> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
mysql> exit

Postfixの設定

vi /etc/postfix/main.cf

Posfixの設定ファイルの最終行に追記します。

# using gmail smtp server to relay mails
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
smtp_tls_CApath = /etc/pki/tls/certs/ca-bundle.crt

ログインユーザー情報ファイルを作成します。

vi /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 xxxx@gmail.com:パスワード

ログインユーザー情報ファイルをハッシュ化し、権限変更してPostfix再起動します

postmap /etc/postfix/sasl_passwd
# /etc/postfix/sasl_passwd.db が生成されます
chown root:root /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd
chown root:root /etc/postfix/sasl_passwd.db
chmod 600 /etc/postfix/sasl_passwd.db
service postfix restart

メールの送信

メールを送信してみます。

echo test | mail xxxx@gmail.com
ログの確認 (日付は省略)
tail -f /var/log/maillog
postfix/pickup[1974]: 363E343762: uid=0 from=
postfix/cleanup[1981]: 363E343762: message-id=<20150204083352.363E343762@centos.localdomain    >
postfix/qmgr[1975]: 363E343762: from=, size=427, nrcpt=1 (queue ac    tive)
postfix/smtp[1983]: connect to smtp.gmail.com[2404:6800:4008:c01::6d]:587: Network is unreach    able
postfix/smtp[1983]: 363E343762: to=, relay=smtp.gmail.com[173.194.72.10    9]:587, delay=3.6, delays=0.02/0.03/2.3/1.3, dsn=2.0.0, status=sent (250 2.0.0 OK 1423038835 b1sm1231475pdi.10 - gsmtp    )
postfix/qmgr[1975]: 363E343762: removed

root宛のメールをGmailに転送

cron処理時に送られるroot宛のメールをGmailに転送することもできます。

vi /etc/aliases

最終行のrootのコメントを外して、アドレスを指定します。
root: xxxx@gmail.com
保存して終了後、aliasesの設定を反映させます。

newaliases

root宛にメール送信テスト

今度はroot宛にメールを送信してみます。

# echo test | mail root

liblcms2をインストール

wget http://pkgrepo.linuxtech.net/el6/release/x86_64/liblcms2-2.4-1.el6.x86_64.rpm
yum install -y liblcms2-2.4-1.el6.x86_64.rpm

libwebpをインストール

yum -y install --enablerepo=epel libwebp

ImageMagick-lastをインストール

yum -y install --enablerepo=remi ImageMagick-last

php-php-gettextインストール

yum -y install --enablerepo=epel php-php-gettext

libmcryptインストール

yum -y install --enablerepo=epel libmcrypt.x86_64

phpMyAdminインストール

yum -y install --enablerepo=remi-php55 phpMyAdmin

phpMyAdmin.confの編集

vi /etc/httpd/conf.d/phpMyAdmin.conf

21行目に以下を追加して、ホストOSからアクセスできるようにします。

Allow from 192.168.56.1

Apacheの設定ファイルを再読み込み。

service httpd reload

ホストOSのブラウザからアクセス確認。
http://192.168.56.101/phpmyadmin/

DocumentRootの変更

ホストOSとゲストOSのどちらからでもファイルを編集できるようにDocumentRootを変更しました。

ここではhtml3フォルダを作成しました。

rm -rf /var/www/html
mkdir /media/sf_Share/html3
ln -s /media/sf_Share/html3 /var/www/html
usermod -G vboxsf apache

共有フォルダはchownもchmodも効かなかったため、apacheユーザーをvboxsfグループに追加しました。

WordPress用のデータベースを作成

mysqlのrootユーザーでwpデータベースを作成します。

mysql -u root -p
Enter password:rootのパスワードを入力
mysql> create database wp;
mysql> exit;

WordPress4.4.2のダウンロード

圧縮ファイルをダウンロードして、解凍します。

cd /media/sf_Share/html3
wget http://ja.wordpress.org/wordpress-4.4.2-ja.tar.gz
tar zxvf wordpress-4.4.2-ja.tar.gz
mv wordpress wp

フォルダ名を「wp」にしました。

WordPress4.4.2の設定ファイルを作成

wp-config-sample.phpをコピーして、wp-config.phpファイルを作成します。

cd wp
mv wp-config-sample.php wp-config.php
vi wp-config.php
/** WordPress のためのデータベース名 */
define('DB_NAME', 'database_name_here');
↓
define('DB_NAME', wp); ←変更(データベース名はwp)

/** MySQL データベースのユーザー名 */
define('DB_USER', 'username_here');
↓
define('DB_USER', 'root'); ←変更(MySQLのrootユーザーを記入)

/** MySQL データベースのパスワード */
define('DB_PASSWORD', 'password_here');
↓
define('DB_PASSWORD', root); ←変更(MySQLのrootパスワードを記入)

WordPressのデータベース名、ユーザー名、パスワードを変更して保存します。

WordPress4.4.2のインストール

httpdを再起動後、ブラウザから以下のURLにアクセスします。

service httpd restart

http://192.168.56.101/wp

必要な項目を入力し、WordPressをインストールします。

以上です。

VirtualBoxのアップデート

Windows8.1にVirtualBox4.3.20をインストールしていましたが、VirtualBoxのバージョンが5.0.14にアップデートしました。

インストーラーをダウンロードして通常通りにインストールをすれば終了です。

そのまま「次へ」で進んだところ、HostOnly NetWorkが2つできました。
1つは削除しておきます。

20160215

以前はCentOSの6.6で環境を作成しましたが、最新のCentOS6.7で同じように環境の構築を試してみます。

CentOSは7もリリースされていますが、まだ試していません。
そのうち試してみようと思います。