1.Vagrant環境の準備
1.BOX追加
vagrant box add Phalcon https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box
2.vagrant init
vagrant init Phalcon
3.Vagrantfile編集
# ホスト名設定
config.vm.hostname = "phalcon.vm"
# 共有ディレクトリ設定
config.vm.synced_folder "/var/www", "/var/www", owner: "apache", group: "apache", mount_options: ["dmode=777", "fmode=777"]
4.起動
vagrant up
エラー出るけど一旦気にせず接続
vagrant ssh
接続したらrootになっておく
su -
※初期パスワードはvagrant
2.CentOSの初期設定をする
1.不要なデーモンをOFF
/sbin/chkconfig auditd off
/sbin/chkconfig lvm2-monitor off
/sbin/chkconfig mdmonitor off
/sbin/chkconfig netfs off
/sbin/chkconfig restorecond off
2.リポジトリ追加
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
yum install -y http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
3.Yumアップデート
yum -y update
4.Vimでも入れとく
1.インストール
yum -y install vim-enhanced
2.エイリアス
echo alias vi='vim' >> /etc/profile
source /etc/profile
3.お好みに設定
cat <<EOF > ~/.vimrc
"構文による色分け
syntax on
"ファイル名表示
set title
"インデントをスペース4つ分に設定
set tabstop=4
"行番号表示
set number
"オートインデント
"set smartindent
"新しい行のインデントを現在行と同じにする
"set autoindent
"ルーラー表示
set ruler
"大文字/小文字の区別なく検索する
set ignorecase
"検索文字列に大文字が含まれている場合は区別して検索する
set smartcase
"検索時に最後まで行ったら最初に戻る
set wrapscan
"タブの代わりに空白文字を指定する
set expandtab
"変更中のファイルでも、保存しないで他のファイルを表示する
set hidden
"インクリメンタルサーチを行う
set incsearch
"閉括弧が入力された時、対応する括弧を強調する
set showmatch
"新しい行を作った時に高度な自動インデントを行う
set smarttab
"表示を見やすくする
set list
set listchars=tab:>-,trail:-,nbsp:%,extends:>,precedes:<
"自動改行しない
set nowrap
"検索時のハイライト
set hlsearch
"行頭、行末からの他行へ移動
set whichwrap=b,s,h,l,<,>,[,],~
"履歴
set history=2000
"ヘルプの言語
set helplang=en
EOF
5.システムの日本語化
yum -y groupinstall "Japanese Support"
localedef -f UTF-8 -i ja_JP ja_JP.utf8
sed -i "s/en_US.UTF-8/ja_JP.utf8/" /etc/sysconfig/i18n
. /etc/sysconfig/i18n
cp /usr/share/zoneinfo/Japan /etc/localtime
sed -i "s/Etc\/UTC/Asia\/Tokyo/" /etc/sysconfig/clock
6.ntpでも入れとく
yum -y install ntp
7.再起動
reboot
3.Apache
1.インストール
yum -y install httpd
2.httpd.conf編集
mv /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bk
cat <<EOF > /etc/httpd/conf/httpd.conf
ServerTokens Prod
ServerRoot "/etc/httpd"
PidFile run/httpd.pid
Timeout 60
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 15
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
<IfModule worker.c>
StartServers 4
MaxClients 300
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
Listen 80
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule info_module modules/mod_info.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule substitute_module modules/mod_substitute.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule cache_module modules/mod_cache.so
LoadModule suexec_module modules/mod_suexec.so
LoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule version_module modules/mod_version.so
Include conf.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
UseCanonicalName Off
DocumentRoot "/var/www"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www">
Options Includes ExecCGI FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<IfModule mod_userdir.c>
UserDir disabled
</IfModule>
DirectoryIndex index.html index.html.var
AccessFileName .htaccess
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</Files>
TypesConfig /etc/mime.types
DefaultType text/plain
<IfModule mod_mime_magic.c>
# MIMEMagicFile /usr/share/magic.mime
MIMEMagicFile conf/magic
</IfModule>
HostnameLookups Off
ErrorLog logs/error_log
LogLevel warn
LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
# LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
SetEnvIf Request_URI "^/favicon\.ico$" no_log
SetEnvIf Request_URI "\.(gif|jpg|png|css|ico|js)$" nolog
SetEnvIf Request_URI "default\.ida" no_log
SetEnvIf Request_URI "cmd\.exe" no_log
SetEnvIf Request_URI "root\.exe" no_log
SetEnvIf Request_URI "Admin\.dll" no_log
SetEnvIf Request_URI "NULL\.IDA" no_log
SetEnvIf Remote_Addr 192.168.1 no_log
SetEnvIf Remote_Addr 127.0.0.1 no_log
CustomLog logs/access_log combined env=!no_log
# CustomLog logs/access_log combined
ServerSignature Off
Alias /icons/ "/var/www/icons/"
<Directory "/var/www/icons">
Options MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<IfModule mod_dav_fs.c>
# Location of the WebDAV lock database.
DAVLockDB /var/lib/dav/lockdb
</IfModule>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8
AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*
AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core
AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^
DefaultIcon /icons/unknown.gif
ReadmeName README.html
HeaderName HEADER.html
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
AddLanguage ca .ca
AddLanguage cs .cz .cs
AddLanguage da .dk
AddLanguage de .de
AddLanguage el .el
AddLanguage en .en
AddLanguage eo .eo
AddLanguage es .es
AddLanguage et .et
AddLanguage fr .fr
AddLanguage he .he
AddLanguage hr .hr
AddLanguage it .it
AddLanguage ja .ja
AddLanguage ko .ko
AddLanguage ltz .ltz
AddLanguage nl .nl
AddLanguage nn .nn
AddLanguage no .no
AddLanguage pl .po
AddLanguage pt .pt
AddLanguage pt-BR .pt-br
AddLanguage ru .ru
AddLanguage sv .sv
AddLanguage zh-CN .zh-cn
AddLanguage zh-TW .zh-tw
LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
ForceLanguagePriority Prefer Fallback
AddDefaultCharset UTF-8
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
AddHandler type-map var
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
Alias /error/ "/var/www/error/"
<IfModule mod_negotiation.c>
<IfModule mod_include.c>
<Directory "/var/www/error">
AllowOverride None
Options IncludesNoExec
AddOutputFilter Includes html
AddHandler type-map var
Order allow,deny
Allow from all
LanguagePriority en es de fr
ForceLanguagePriority Prefer Fallback
</Directory>
</IfModule>
</IfModule>
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0
BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "MS FrontPage" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully
BrowserMatch "^gnome-vfs/1.0" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully
EOF
3.起動&自動起動設定
/etc/rc.d/init.d/httpd start
chkconfig httpd on
4.MySQL5.6
1.インストール
yum -y install mysql-community-server
2.ログディレクトリ作成
mkdir /var/log/mysql && chown mysql:mysql /var/log/mysql
3.my.cnf編集
mv /etc/my.cnf /etc/my.cnf.bk
cat <<EOF > /etc/my.cnf
[client]
default-character-set=utf8
[mysqld]
# データディレクトリ
datadir=/var/lib/mysql
# pidパス
pid-file=/var/run/mysqld/mysqld.pid
# 文字コード関連
skip-character-set-client-handshake
character-set-server=utf8
collation-server=utf8_general_ci
init-connect=SET NAMES utf8
# デフォルトストレージエンジン
default-storage-engine=innodb
# エラーログ
log-error=/var/log/mysql/error.log
# クエリログ
general_log=1
general_log_file=/var/log/mysql/query.log
# スロークエリログ
long_query_time=1
slow_query_log=1
slow_query_log_file=/var/log/mysql/slow.log
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/var/log/mysql/error.log
pid-file=/var/run/mysqld/mysqld.pid
[mysqldump]
default-character-set=utf8
[mysql]
default-character-set=utf8
EOF
4.起動&自動起動設定
service mysqld start
chkconfig mysqld on
4.セットアップ
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を再起動
/etc/init.d/mysqld restart
5.PHP5.6
1.インストール(使いそうなものもついでに)
yum --enablerepo=remi,remi-php56 -y install php php-common php-cli php-devel 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
6.Composer
cd /tmp && curl -s http://getcomposer.org/installer | php
mv /tmp/composer.phar /usr/local/bin/composer
7.Pahlcon2
cd /usr/local && git clone --depth=1 git://github.com/phalcon/cphalcon.git
cd cphalcon/build && ./install
echo extension=phalcon.so >> /etc/php.d/phalcon.ini
8.Phalconデベロッパーツール
mkdir /usr/local/phalcon-devtool && cd $_
cat <<EOF > composer.json
{
"require": {
"phalcon/devtools": "dev-master"
}
}
EOF
composer install
ln -s /usr/local/phalcon-devtool/vendor/phalcon/devtools/phalcon.php /usr/bin/phalcon
chmod ugo+x /usr/bin/phalcon
9.おまけに色々入れとく
Zephir
yum -y install json-c
yum -y install re2c
cd /usr/local/src
git clone https://github.com/phalcon/zephir
cd zephir
./install-json
./install -c
xhprof
pecl install xhprof channel://pecl.php.net/xhprof-0.9.4
echo extension=xhprof.so >> /etc/php.d/xhprof.ini
memcached
yum --enablerepo=remi,epel -y install memcached memcached-devel
/etc/init.d/memcached start
chkconfig memcached on
memcachedをPHPをで使えるようにする
yum --enablerepo=remi,remi-php56 -y install php-pecl-memcached
Redis
yum --enablerepo=remi,epel -y install redis
/etc/init.d/redis start
chkconfig redis on
RedisをPHPをで使えるようにする
yum --enablerepo=remi,remi-php56 -y install php-pecl-redis
mecab
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
mecabを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
ImageMagick
yum -y install --enablerepo=remi ImageMagick-last
ImageMagickをPHPで使えるようにする
yum --enablerepo=remi-php56 install php-pecl-imagick php-pecl-imagick-devel
phpMyAdmin
cd /use/local/src
wget http://files.phpmyadmin.net/phpMyAdmin/4.4.14/phpMyAdmin-4.4.14-all-languages.tar.gz
tar zxvf phpMyAdmin-4.4.14-all-languages.tar.gz
mv /use/local/src/phpMyAdmin-4.4.14-all-languages /use/local/src/phpMyAdmin
mkdir /var/log/httpd/phpmyadmin
# VirtualHostで設定する場合
<VirtualHost *:80>
ServerName phpmyadmin.vm
DocumentRoot /use/local/src/phpMyAdmin
ErrorLog /var/log/httpd/phpmyadmin/error_log
CustomLog /var/log/httpd/phpmyadmin/access_log combined env=!no_log
<Directory "/use/local/src/phpMyAdmin">
Options Includes ExecCGI FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
EOF
10.構築した環境をパッケージ化する
1.MACアドレスのマッピングを無効にする(ゲストOS側)
ln -s -f /dev/null /etc/udev/rules.d/70-persistent-net.rules
2.空き容量をゼロ埋め(ゲストOS側)
dd if=/dev/zero of=/tmp/ZERO bs=1M
3.パッケージ化(ホストOS側)
vagrant package --output PhalconCent6.box