vagrantでCentOS7+Apache2.4+PHP7+MySQL5.7+CakePHP3の環境を作る

まずはvagrantでCentOS7の設定

user@user MINGW64 ~/vagrant
$ mkdir centos7

user@user MINGW64 ~/vagrant
$ cd centos7

user@user MINGW64 ~/vagrant/centos7
$ vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

Vagrantfileができるので必要箇所を編集

config.vm.box = "centos/7"
config.vm.network "forwarded_port", guest: 80, host: 8003
config.vm.synced_folder ".", "/vagrant", type:"virtualbox"

vagrant upで立ち上げる

user@user MINGW64 ~/vagrant/centos7
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'centos/7' is up to date...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 80 (guest) => 8003 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key

Apache

vagrant sshで接続
user@user MINGW64 ~/vagrant/centos7
$ vagrant ssh
[vagrant@localhost ~]$

インストール
[vagrant@localhost ~]$ su -
[root@localhost ~]# yum -y install httpd

バージョン確認
[root@localhost ~]# httpd -v

起動
[root@localhost ~]# systemctl start httpd

自動起動設定
[root@localhost ~]# systemctl enable httpd.service

mysql

mariaDBの削除
[root@localhost ~]# yum -y remove mariadb-libs.x86_64

リポジトリ追加
[root@localhost ~]# yum -y install http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

インストール
[root@localhost ~]# yum -y install mysql-community-server

バージョン確認
[root@localhost ~]# mysqld --version

起動
[root@localhost ~]# systemctl start mysqld

自動起動設定
[root@localhost ~]# systemctl enable mysqld

PHP7

EPELリポジトリ
[root@localhost ~]# yum -y install epel-release

Remiリポジトリ
[root@localhost ~]# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

php7インストール
[root@localhost ~]# yum -y install --enablerepo=remi,epel,remi-php70 php php-devel php-intl php-mbstring php-pdo php-gd php-mysqlnd

バージョン確認
[root@localhost ~]# php -v

composer

composerを使ってCakePHP3をインストールするので先にインストールしておく。

[root@localhost ~]# php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
[root@localhost ~]# php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
[root@localhost ~]# php composer-setup.php
[root@localhost ~]# php -r "unlink('composer-setup.php');"
[root@localhost ~]# mv composer.phar /usr/local/bin/composer

CakePHP3

[root@localhost ~]# cd /opt/www
[root@localhost www]# composer self-update && composer create-project --prefer-dist cakephp/app cakephp3
You are already using composer version 1.5.2 (stable channel).
Installing cakephp/app (3.5.0)
    Failed to download cakephp/app from dist: The zip extension and unzip command are both missing, skipping.
The php.ini used by your command-line PHP is: /etc/php.ini
    Now trying to download from source
  - Installing cakephp/app (3.5.0): Cloning f807e4ef14
Created project in cakephp3
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - cakephp/cakephp-codesniffer 3.0.0 requires squizlabs/php_codesniffer ^3.0.0 -> satisfiable by squizlabs/php_codesniffer[3.0.0, 3.0.1, 3.0.2, 3.1.0, 3.1.1].
    - cakephp/cakephp-codesniffer 3.0.1 requires squizlabs/php_codesniffer ^3.0.0 -> satisfiable by squizlabs/php_codesniffer[3.0.0, 3.0.1, 3.0.2, 3.1.0, 3.1.1].
    - squizlabs/php_codesniffer 3.1.1 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
    - squizlabs/php_codesniffer 3.1.0 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
    - squizlabs/php_codesniffer 3.0.2 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
    - squizlabs/php_codesniffer 3.0.1 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
    - squizlabs/php_codesniffer 3.0.0 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
    - Installation request for cakephp/cakephp-codesniffer ^3.0 -> satisfiable by cakephp/cakephp-codesniffer[3.0.0, 3.0.1].

  To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php.ini
    - /etc/php.d/20-bz2.ini
    - /etc/php.d/20-calendar.ini
    - /etc/php.d/20-ctype.ini
    - /etc/php.d/20-curl.ini
    - /etc/php.d/20-exif.ini
    - /etc/php.d/20-fileinfo.ini
    - /etc/php.d/20-ftp.ini
    - /etc/php.d/20-gd.ini
    - /etc/php.d/20-gettext.ini
    - /etc/php.d/20-iconv.ini
    - /etc/php.d/20-intl.ini
    - /etc/php.d/20-json.ini
    - /etc/php.d/20-mbstring.ini
    - /etc/php.d/20-mysqlnd.ini
    - /etc/php.d/20-pdo.ini
    - /etc/php.d/20-phar.ini
    - /etc/php.d/20-sockets.ini
    - /etc/php.d/20-sqlite3.ini
    - /etc/php.d/20-tokenizer.ini
    - /etc/php.d/30-mysqli.ini
    - /etc/php.d/30-pdo_mysql.ini
    - /etc/php.d/30-pdo_sqlite.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

色々エラーが出たので足りないのをインストールしていく。

php_codesniffer

[root@localhost www]# composer global require "squizlabs/php_codesniffer=*"
Changed current directory to /root/.config/composer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
    Failed to download squizlabs/php_codesniffer from dist: The zip extension and unzip command are both missing, skipping.
The php.ini used by your command-line PHP is: /etc/php.ini
    Now trying to download from source
  - Installing squizlabs/php_codesniffer (2.2.0): Cloning b301c98f19
Writing lock file
Generating autoload files

zipとunzip

[root@localhost www]# sudo yum install zip unzip

php-xml

[root@localhost ~]# yum -y install --enablerepo=remi,epel,remi-php70 php-xml

php_codesniffer

[root@localhost ~]# composer global  require "squizlabs/php_codesniffer=*"

再度CakePHP3

[root@localhost www]# composer self-update && composer create-project --prefer-dist cakephp/app cakephp3

完了。