CentOS7.0+HHVM3.5+Symfony2+WebScaleSQL Server環境構築

#前提条件

以下の作業が完了しているものとする。

CentOS7.0 + HHVM3.5 + Nginx環境構築
http://qiita.com/nyatakasan/items/f2851809aa5e3f1ad709

#WebScaleSQL Server
```shell-session
$ sudo yum install mysql-server mysql --nogpgcheck
$ sudo cat /etc/my.cnf <<_EOF_
[mysqld]
# --------------------------------------------------
# Base
# --------------------------------------------------
user = mysql
port = 3306
datadir = /var/lib/mysql
socket  = /var/lib/mysql/mysql.sock
pid-file = /var/run/mysqld/mysqld.pid
symbolic-links = 0
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
default-storage-engine = InnoDB
transaction-isolation = REPEATABLE-READ
character-set-server = utf8
collation-server = utf8_general_ci
skip-character-set-client-handshake

# --------------------------------------------------
# Replication
# --------------------------------------------------
# not use Replication for now
server-id	= 1
log-bin = mysql-bin

# --------------------------------------------------
# Network
# --------------------------------------------------
# Global
skip-networking
skip-name-resolve
max_connections = 300
max_connect_errors = 999999999
connect_timeout = 10
max_allowed_packet = 16M
# Global, Session
max_user_connections = 0
wait_timeout = 600
interactive_timeout = 600

# --------------------------------------------------
# Logging
# --------------------------------------------------
log_output = FILE
log_warnings = 1
general_log = 0
general_log_file = /var/log/mysql/query.log
log-slow-admin-statements = 1
log-queries-not-using-indexes = 1
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 0.5
expire_logs_days = 14

# --------------------------------------------------
# Cache &amp; Memory
# --------------------------------------------------
# Global
thread_cache_size = 30
table_open_cache = 400
query_cache_size = 16M
query_cache_limit = 1M
# Global, Session
max_heap_table_size = 16M
tmp_table_size = 16M
sort_buffer_size = 2M
read_buffer_size = 131072
join_buffer_size = 131072
read_rnd_buffer_size = 262144

# --------------------------------------------------
# MyISAM
# --------------------------------------------------
# Global
skip-external-locking
key_buffer_size = 8M
myisam_max_sort_file_size = 2G
myisam_recover_options = DEFAULT
# Global, Session
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M

# --------------------------------------------------------------------
# InnoDB behavior
# --------------------------------------------------------------------
# Global
innodb_file_format = Barracuda
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_stats_on_metadata = 1
innodb_max_dirty_pages_pct = 90
innodb_adaptive_hash_index = 1
innodb_adaptive_flushing = 1
innodb_strict_mode = 1
innodb_io_capacity = 200
innodb_autoinc_lock_mode = 1
innodb_change_buffering = inserts
innodb_old_blocks_time = 500

# --------------------------------------------------------------------
# InnoDB base
# --------------------------------------------------------------------
# Global
innodb_buffer_pool_size = 256M
innodb_data_home_dir = /var/lib/mysql
innodb_data_file_path = ibdata1:1000M:autoextend
innodb_file_per_table = 1
innodb_autoextend_increment = 64M
innodb_log_group_home_dir = /var/lib/mysql
innodb_fast_shutdown = 0
innodb_log_file_size = 64M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 8M
innodb_additional_mem_pool_size = 8M
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 1
innodb_force_recovery = 0
innodb_doublewrite = 1
innodb_sync_spin_loops = 20
innodb_thread_sleep_delay = 1000
innodb_commit_concurrency = 0
innodb_concurrency_tickets = 500
# Global, Session
innodb_support_xa = FALSE
innodb_lock_wait_timeout = 50
innodb_table_locks = 1
innodb_api_trx_level = 2

[mysqldump]
default-character-set = utf8
quick
max_allowed_packet = 16M

[mysql]
default-character-set = utf8
no-auto-rehash
show-warnings

[client]
default-character-set = utf8
port   = 3306
socket = /var/lib/mysql/mysql.sock

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

!includedir /etc/my.cnf.d
_EOF_
```
※[my.cnf設定サンプル](http://time-complexity.blogspot.jp/2013/10/mysqlmycnf.html)

#Nginx設定

```shell-session
sed -i 's|date.timezone = Asia/Calcutta|date.timezone = Asia/Tokyo|g' /etc/hhvm/server.ini
echo 'hhvm.libxml.ext_entity_whitelist = file,http' >> /etc/hhvm/server.ini
```

# Composer設定

```shell-session
# 適当に移動
$ cd /usr/local/src
$ sudo wget https://getcomposer.org/installer
$ hhvm -v ResourceLimit.SocketDefaultTimeout=30 -v Http.SlowQueryThreshold=30000 installer
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo rm installer
$ composer --version
Composer version 1.0-dev (b296e654eb3e136ca6fa08fa3bcb1d4782c13f8b) 2015-03-09 11:13:01
```

#公開ディレクトリに移動

```shell-session
git clone -b hhvm https://github.com/E1379/symfony-standard.git <<インストール先ディレクトリ>>
sudo chmod 777 /<<インストール先ディレクトリ>>/app/cache
sudo chmod 777 /<<インストール先ディレクトリ>>/app/logs
```

#Symfony2コマンド動作確認

```shell-session
$sudo hhvm -c /etc/hhvm/php.ini -c /etc/hhvm/server.ini app/check.php
Symfony2 Requirements Checker


> PHP is using the following php.ini file:
[Mon Apr 20 05:38:02 2015] [hphp] [22627:7f442898e740:0:000009] []
Notice: Undefined index: warning in /opt/web-api.info/app/check.php on line 113
  WARNING: No configuration file (php.ini) used by PHP!

> Checking Symfony requirements:
  .........................W.............


 [OK]
 Your system is ready to run Symfony2 projects


Optional recommendations to improve your setup

 * iconv() should be available
   \> Install and enable the iconv extension.


Note  The command console could use a different php.ini file
~~~~  than the one used with your web server. To be on the
      safe side, please check the requirements from your web
      server using the web/config.php script.
```

```shell-session
$sudo hhvm -c /etc/hhvm/php.ini -c /etc/hhvm/server.ini app/console
Symfony version 2.6.6 - app/dev/debug

Usage:
 command [options] [arguments]

Options:
 --help (-h)           Display this help message
 --quiet (-q)          Do not output any message
 --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
 --version (-V)        Display this application version
 --ansi                Force ANSI output
 --no-ansi             Disable ANSI output
 --no-interaction (-n) Do not ask any interactive question
 --shell (-s)          Launch the shell.
 --process-isolation   Launch commands from shell as a separate process.
 --env (-e)            The Environment name. (default: "dev")
 --no-debug            Switches off debug mode.

Available commands:
 help                                  Displays help for a command
 list                                  Lists commands
assetic
 assetic:dump                          Dumps all assets to the filesystem
 assetic:watch                         Dumps assets to the filesystem as their source files are modified
assets
 assets:install                        Installs bundles web assets under a public web directory
cache
 cache:clear                           Clears the cache
 cache:warmup                          Warms up an empty cache
config
 config:debug                          Dumps the current configuration for an extension
 config:dump-reference                 Dumps the default configuration for an extension
container
 container:debug                       Displays current services for an application
debug
 debug:config                          Dumps the current configuration for an extension
 debug:container                       Displays current services for an application
 debug:event-dispatcher                Displays configured listeners for an application
 debug:router                          Displays current routes for an application
 debug:swiftmailer                     Displays current mailers for an application
 debug:translation                     Displays translation messages informations
 debug:twig                            Shows a list of twig functions, filters, globals and tests
doctrine
 doctrine:cache:clear-metadata         Clears all metadata cache for an entity manager
 doctrine:cache:clear-query            Clears all query cache for an entity manager
 doctrine:cache:clear-result           Clears result cache for an entity manager
 doctrine:database:create              Creates the configured databases
 doctrine:database:drop                Drops the configured databases
 doctrine:ensure-production-settings   Verify that Doctrine is properly configured for a production environment.
 doctrine:generate:crud                Generates a CRUD based on a Doctrine entity
 doctrine:generate:entities            Generates entity classes and method stubs from your mapping information
 doctrine:generate:entity              Generates a new Doctrine entity inside a bundle
 doctrine:generate:form                Generates a form type class based on a Doctrine entity
 doctrine:mapping:convert              Convert mapping information between supported formats.
 doctrine:mapping:import               Imports mapping information from an existing database
 doctrine:mapping:info
 doctrine:query:dql                    Executes arbitrary DQL directly from the command line.
 doctrine:query:sql                    Executes arbitrary SQL directly from the command line.
 doctrine:schema:create                Executes (or dumps) the SQL needed to generate the database schema
 doctrine:schema:drop                  Executes (or dumps) the SQL needed to drop the current database schema
 doctrine:schema:update                Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata.
 doctrine:schema:validate              Validate the mapping files.
generate
 generate:bundle                       Generates a bundle
 generate:controller                   Generates a controller
 generate:doctrine:crud                Generates a CRUD based on a Doctrine entity
 generate:doctrine:entities            Generates entity classes and method stubs from your mapping information
 generate:doctrine:entity              Generates a new Doctrine entity inside a bundle
 generate:doctrine:form                Generates a form type class based on a Doctrine entity
init
 init:acl                              Mounts ACL tables in the database
orm
 orm:convert:mapping                   Convert mapping information between supported formats.
router
 router:debug                          Displays current routes for an application
 router:dump-apache                    Dumps all routes as Apache rewrite rules
 router:match                          Helps debug routes by simulating a path info match
security
 security:check                        Checks security issues in your project dependencies
swiftmailer
 swiftmailer:debug                     Displays current mailers for an application
 swiftmailer:email:send                Send simple email message
 swiftmailer:spool:send                Sends emails from the spool
translation
 translation:debug                     Displays translation messages informations
 translation:update                    Updates the translation file
twig
 twig:debug                            Shows a list of twig functions, filters, globals and tests
 twig:lint                             Lints a template and outputs encountered errors
yaml
 yaml:lint                             Lints a file and outputs encountered errors
```