26
27

More than 5 years have passed since last update.

Vagrant+CentOS7.1でLAMP+Zephir+Phalcon2環境を作る

Last updated at Posted at 2015-06-09

Vagrant Boxを入れる

1.BOX追加
vagrant box add CentOS7 https://github.com/holms/vagrant-centos7-box/releases/download/7.1.1503.001/CentOS-7.1.1503-x86_64-netboot.box
2.init
mkdir /vagrant/CentOS7 && cd $_
vagrant init CentOS7
3.Vagrantfile編集
vim Vagrantfile

#お好みで!
config.vm.synced_folder "/var/www", "/var/www", owner: "apache", group: "apache", mount_options: ["dmode=777", "fmode=777"]

CentOS7.1の初期設定

1.リポジトリ登録

リポジトリ優先度プラグイン
yum -y install yum-plugin-priorities
epel
yum -y install epel-release

#デフォルトで呼ばないように
sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/epel.repo
RPMforge
yum -y install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm

#デフォルトで呼ばないように
sed -i -e "s/enabled = 1/enabled = 0/g" /etc/yum.repos.d/rpmforge.repo
remi
yum -y install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
MySQL
yum -y install http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2.yum update

yum -y update

3.時刻同期設定

1.chronyインストール&サービス登録
yum install -y chrony
systemctl enable chronyd
2.同期サーバーを日本のサーバーに設定
vim /etc/chrony.conf
-----------------------------------------
server ntp.nict.jp iburst
server ntp1.jst.mfeed.ad.jp iburst
server ntp2.jst.mfeed.ad.jp iburst
server ntp3.jst.mfeed.ad.jp iburst
-----------------------------------------
3.chronyd再起動
systemctl start chronyd
4.タイムゾーンをAsia/Tokyoに設定
timedatectl set-timezone Asia/Tokyo

4.Vim入れとこっ

インストール
yum -y install vim-enhanced
viとして使えるようにエイリアス
echo alias vi='vim' >> /etc/profile
source /etc/profile

5.Firewall止める

systemctl stop firewalld
systemctl disable firewalld

6.日本語対応にする

NKF
wget "http://sourceforge.jp/frs/redir.php?m=jaist&f=%2Fnkf%2F59912%2Fnkf-2.1.3.tar.gz" -O nkf-2.1.3.tar.gz
tar zxvf nkf-2.1.3.tar.gz
cd nkf-2.1.3
make && make install
rm -rf nkf-2.1.3*
ln -s /usr/local/bin/nkf /usr/bin/nkf
日本語関連パッケージ
yum -y install ibus-kkc vlgothic-*
システム文字セット変更
localectl set-locale LANG=ja_JP.UTF-8
source /etc/locale.conf 

7.一旦reboot

reboot

LMAP環境を作る

Apache

1.インストール&サービス登録

インストール
yum -y install httpd
サービス登録
systemctl enable httpd

MySQL

1.インストール&サービス登録

インストール
yum -y install mysql-community-server
※デフォルトバージョンは5.6のはず
サービス登録
systemctl enable mysqld

2.初期設定

my.cnf編集
mv /etc/my.cnf /etc/my.cnf.bk
cat <<EOF > /etc/my.cnf
[client]
default-character-set=utf8

[mysqld]
skip-character-set-client-handshake
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = SET NAMES utf8
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysqldump]
default-character-set=utf8

[mysql]
default-character-set=utf8
EOF
セットアップ
mysql_secure_installation
>Enter current password for root (enter for none):
[何も入力せずEnter]

# root ユーザーのパスワードを変更するか?
>Change the root password? [Y/n]
['Y'を入力してEnter]
>New password:
[パスワードを入力してEnter]
>Re-enter new password:
[パスワード入力してEnter]
# 匿名ユーザーを削除するか?
>Remove anonymous users? [Y/n]
['Y'を入力してEnter]
# リモートから root ユーザーのログインを禁止するか?
Disallow root login remotely? [Y/n]
['Y'を入力してEnter]
# test データベースを削除するか?
>Remove test database and access to it? [Y/n]
['Y'を入力してEnter]
# 権限テーブルをリロードするか?
>Reload privilege tables now? [Y/n]
['Y'を入力してEnter]

# MySQLを再起動
systemctl restart mysqld

PHP5.6

1.インストール

本体インストール
yum --enablerepo=remi-php56 -y install php php-devel
使いそうなものインストール
yum --enablerepo=epel,remi,remi-php56 -y install php-gd php-mbstring php-mcrypt php-xml php-pear php-pdo php-mysqlnd php-pecl-apc php-sqlite

2.初期設定

php.ini編集
# タイムゾーン設定
sed -i "s/;date.timezone =/date.timezone = 'Asia\/Tokyo'/" /etc/php.ini

# mbstring系の設定
sed -i "s/;mbstring.language = Japanese/mbstring.language = Japanese/" /etc/php.ini
sed -i "s/;mbstring.internal_encoding =/mbstring.internal_encoding = UTF-8/" /etc/php.ini
sed -i "s/;mbstring.http_input =/mbstring.http_input = UTF-8/" /etc/php.ini

xhprof

インストール
pecl install xhprof channel://pecl.php.net/xhprof-0.9.4
iniファイル追加
echo extension=xhprof.so >> /etc/php.d/xhprof.ini

Composer

インストール
cd /tmp && curl -s http://getcomposer.org/installer | php
composerコマンドで使えるようにする
mv /tmp/composer.phar /usr/local/bin/composer

Phalcon2

re2cインストール
yum -y install http://pkgs.repoforge.org/re2c/re2c-0.13.5-1.el6.rf.x86_64.rpm
Zephirインストール
cd /usr/local/src
git clone https://github.com/phalcon/zephir
git clone https://github.com/phalcon/json-c zephir/json-c
cd zephir
./install-json
./install -c
Phalcon2をyumでインストール
yum --enablerepo=remi-php56 -y install php-phalcon2

@kenjis様よりコメントにてremiリポジトリにPhalcon2が存在するとの情報をご提供いただきましたので、コンパイルでのインストール方法は削除いたしました。

devtoolインストール
mkdir /usr/local/phalcon-devtool && cd $_
cat <<EOF > composer.json
{
  "require": {
    "phalcon/devtools": "dev-master"
  }
}
EOF
composer install
phalconコマンドとして使えるように
ln -s /usr/local/phalcon-devtool/vendor/phalcon/devtools/phalcon.php /usr/bin/phalcon
chmod ugo+x /usr/bin/phalcon

KVS

memcached

1.インストール

インストール
yum --enablerepo=remi -y install memcached
起動
systemctl start memcached
サービス登録
systemctl enable memcached

2.PHPで使えるようにする

パッケージインストール
yum --enablerepo=remi-php56 -y install php-pecl-memcached

Redis

1.インストール

インストール
yum --enablerepo=epel,remi -y install redis
起動
systemctl start redis
サービス登録
systemctl enable redis

2.PHPで使えるようにする

パッケージインストール
yum --enablerepo=remi-php56 -y install php-pecl-redis

その他

ImageMagick

1.インストール

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

2.PHPで使えるようにする

yum --enablerepo=remi-php56 -y install php-pecl-imagick php-pecl-imagick-devel

Mecab

1.インストール

yum -y install gcc-c++ wget
mkdir /usr/local/mecab && cd $_
wget http://mecab.googlecode.com/files/mecab-0.996.tar.gz
tar xvfz mecab-0.996.tar.gz
cd mecab-0.996 && ./configure
make && make check && make install
cd /usr/local/mecab
wget http://mecab.googlecode.com/files/mecab-ipadic-2.7.0-20070801.tar.gz
tar xvfz mecab-ipadic-2.7.0-20070801.tar.gz
cd mecab-ipadic-2.7.0-20070801 && ./configure --with-charset=utf8
make && make install

2.PHPで使えるようにする

pear channel-discover pecl.opendogs.org
pear remote-list -c opendogs
pear install opendogs/mecab-beta
> specify pathname to mecab-config [no] : [空エンター]
※/usr/lib64/php/modules/mecab.so にインストールされるはず

echo extension=mecab.so >> /etc/php.d/mecab.ini
26
27
3

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
26
27