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

完了。

CentOS5.1にGitをインストールする

CentOSが5.1でもGitは使いたい。
※1年くらい前の作業メモなので今でもこの通りいくか不明。
※自己責任で試しましょう。


参考にさせていただいた記事はこちら。
CentOS5.8にyumでgitをインストールする | hypermkt blog

とりあえず普通にyumでインストールしてみる。

[vagrant@localhost ~]$ sudo yum -y install git
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
Setting up Install Process
No package git available.
Nothing to do

No package git available.だって。
どうやらCentOSのデフォルトのyumリポジトリではgitがないらしい。

epelリポジトリの入手

[vagrant@localhost ~]$ sudo rpm -ivh http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/5/x86_64/epel-release-5-4.noarch.rpm
Retrieving http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/5/x86_64/epel-release-5-4.noarch.rpm
warning: /var/tmp/rpm-xfer.oDCufz: Header V3 DSA signature: NOKEY, key ID 217521f6
Preparing...                ########################################### [100%]
   1:epel-release           ########################################### [100%]

このままだとepelリポジトリCentOSの公式リポジトリより優先されてしまうようなので、
公式リポジトリを優先するように設定しておかないといけない。
てことでどのリポジトリを優先的に利用するか設定するためにyum-prioritiesをインストールする。

yum-prioritiesのインストー

[vagrant@localhost ~]$ sudo yum install yum-priorities
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * epel: ftp.kddilabs.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
epel                                                                                                                                            | 3.6 kB     00:00
epel/primary_db                                                                                                                                 | 2.9 MB     00:00
Setting up Install Process
Resolving Dependencies
 --> Running transaction check
 ---> Package yum-priorities.noarch 0:1.1.16-21.el5.centos set to be updated
 --> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
 Package                                    Arch                               Version                                          Repository                        Size
=======================================================================================================================================================================
Installing:
 yum-priorities                             noarch                             1.1.16-21.el5.centos                             base                              16 k

Transaction Summary
=======================================================================================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 16 k
Is this ok [y/N]: y
Downloading Packages:
yum-priorities-1.1.16-21.el5.centos.noarch.rpm                                                                                                  |  16 kB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : yum-priorities                                                                                                                                  1/1

Installed:
  yum-priorities.noarch 0:1.1.16-21.el5.centos

Complete!

yum-prioritiesがインストールできたら、
baseのprioirtyを1で、他を2とかにすればいける。(たぶん)

Baseリポジトリの優先度を上げる

[vagrant@localhost ~]$ sudo vi /etc/yum.repos.d/CentOS-Base.repo
[base]
...
 +priority=1
 
#released updates
[updates]
...
 +priority=2
 
#additional packages that may be useful
[extras]
...
 +priority=2
 
#additional packages that extend functionality of existing packages
[centosplus]
...
 +priority=2
 
#contrib - packages by Centos Users
[contrib]
...
 +priority=2

Gitをインストールする

[vagrant@localhost ~]$ sudo yum install git
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * epel: ftp.kddilabs.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
base                                                                                                                                            | 1.1 kB     00:00
extras                                                                                                                                          | 2.1 kB     00:00
updates                                                                                                                                         | 1.9 kB     00:00
Setting up Install Process
Resolving Dependencies
 --> Running transaction check
 ---> Package git.x86_64 0:1.8.2.3-1.el5 set to be updated
 --> Processing Dependency: perl-Git = 1.8.2.3-1.el5 for package: git
 --> Processing Dependency: rsync for package: git
 --> Processing Dependency: perl(Term::ReadKey) for package: git
 --> Processing Dependency: perl(Git) for package: git
 --> Processing Dependency: perl(Error) for package: git
 --> Running transaction check
 ---> Package perl-Error.noarch 1:0.17010-1.el5 set to be updated
 ---> Package perl-Git.x86_64 0:1.8.2.3-1.el5 set to be updated
 ---> Package perl-TermReadKey.x86_64 0:2.30-4.el5 set to be updated
 ---> Package rsync.x86_64 0:3.0.6-6.el5_11 set to be updated
 --> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
 Package                                      Arch                               Version                                     Repository                           Size
=======================================================================================================================================================================
Installing:
 git                                          x86_64                             1.8.2.3-1.el5                               epel                                 17 M
Installing for dependencies:
 perl-Error                                   noarch                             1:0.17010-1.el5                             epel                                 26 k
 perl-Git                                     x86_64                             1.8.2.3-1.el5                               epel                                 45 k
 perl-TermReadKey                             x86_64                             2.30-4.el5                                  epel                                 32 k
 rsync                                        x86_64                             3.0.6-6.el5_11                              updates                             347 k

Transaction Summary
=======================================================================================================================================================================
Install       5 Package(s)
Upgrade       0 Package(s)

Total download size: 17 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): perl-Error-0.17010-1.el5.noarch.rpm                                                                                                      |  26 kB     00:00
(2/5): perl-TermReadKey-2.30-4.el5.x86_64.rpm                                                                                                   |  32 kB     00:00
(3/5): perl-Git-1.8.2.3-1.el5.x86_64.rpm                                                                                                        |  45 kB     00:00
(4/5): rsync-3.0.6-6.el5_11.x86_64.rpm                                                                                                          | 347 kB     00:00
(5/5): git-1.8.2.3-1.el5.x86_64.rpm                                                                                                             |  17 MB     00:03
 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                  3.1 MB/s |  17 MB     00:05
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 217521f6
epel/gpgkey                                                                                                                                     | 1.7 kB     00:00
Importing GPG key 0x217521F6 "Fedora EPEL " from /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : perl-Error                                                                                                                                      1/5
  Installing     : perl-TermReadKey                                                                                                                                2/5
  Installing     : rsync                                                                                                                                           3/5
  Installing     : git                                                                                                                                             4/5
  Installing     : perl-Git                                                                                                                                        5/5

Installed:
  git.x86_64 0:1.8.2.3-1.el5

Dependency Installed:
  perl-Error.noarch 1:0.17010-1.el5         perl-Git.x86_64 0:1.8.2.3-1.el5         perl-TermReadKey.x86_64 0:2.30-4.el5         rsync.x86_64 0:3.0.6-6.el5_11

Complete!
[vagrant@localhost ~]$ git --version
git version 1.8.2.3

無事インストールできました。

VagrantでCentOS5.1の開発環境を作る

CentOSの5系で開発してくれって言うお客さんがいたので、
四苦八苦しながら環境構築したときのメモの書き起こし。
1年くらい前の作業メモなので今でもこの通りいくか不明。
※自己責任で試しましょう。

環境

Windows 7
VirtualBox 5.0.14
Vagrant 1.8.1

CentOS5.1のboxを持ってくる。

$ mkdir vagrant
$ cd vagrant
$ mkdir centos5
$ cd centos5
$ vagrant box add centos5.1 http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-5.10_chef-provisionerless.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'centos5.1' (v0) for provider:
    box: Downloading: http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-5.10_chef-provisionerless.box
    box:
==> box: Successfully added box 'centos5.1' (v0) for 'virtualbox'!

//boxが追加されたか確認
$ vagrant box list
centos5.1        (virtualbox, 0)
//立ち上げる
$ vagrant init centos5.1
$ vagrant up

(長いので略)

Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

The error output from the last command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

なんかマウントが失敗したっぽいエラー。
下記の記事がそのまま参考になりました。
qiita.com

よくわからんがカーネルのソースへのパス設定しなおさないとダメっぽい。

カーネルの設定。

//vagrant sshでログイン
$ vagrant ssh
//kernel-develインストールする
[vagrant@localhost ~]$ sudo yum install kernel-devel -y
[vagrant@localhost ~]$ ls /usr/src/kernels/
2.6.18-412.el5-x86_64
[vagrant@localhost ~]$ uname -r
2.6.18-371.el5
[vagrant@localhost ~]$ su -
[root@localhost ~]# echo "KERN_DIR=/usr/src/kernels/2.6.18-406.el5-x86_64" >> .bash_profile
[root@localhost ~]# yum info kernel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.nara.wide.ad.jp
 * extras: ftp.nara.wide.ad.jp
 * updates: ftp.nara.wide.ad.jp
Installed Packages
Name       : kernel
Arch       : x86_64
Version    : 2.6.18
Release    : 371.el5
Size       : 99 M
Repo       : installed
Summary    : The Linux kernel (the core of the Linux operating system)
URL        : http://www.kernel.org/
License    : GPLv2
Description: The kernel package contains the Linux kernel (vmlinuz), the core of any
           : Linux operating system.  The kernel handles the basic functions
           : of the operating system:  memory allocation, process allocation, device
           : input and output, etc.

Available Packages
Name       : kernel
Arch       : x86_64
Version    : 2.6.18
Release    : 412.el5
Size       : 22 M
Repo       : updates
Summary    : The Linux kernel (the core of the Linux operating system)
URL        : http://www.kernel.org/
License    : GPLv2
Description: The kernel package contains the Linux kernel (vmlinuz), the core of any
           : Linux operating system.  The kernel handles the basic functions
           : of the operating system:  memory allocation, process allocation, device
           : input and output, etc.
[root@localhost ~]# yum update kernel -y
[root@localhost ~]# shutdown -r now

vbGuest Additionsのアップデート

$ vagrant vbguest
Guest-specific operations were attempted on a machine that is not
ready for guest communication. This should not happen and a bug
should be reported.
$ vagrant reload

たぶんこれでうまく立ち上がるはず。

VagrantでCentOSを使ってローカル開発環境を整える

Vagrantをダウンロードする

下記からダウンロード
https://www.vagrantup.com/downloads.html
バージョンは1.8.1だった。

CentOSを立ち上げる

続きを読む

Gitに入門する -その10-

blog.takanabe.tokyo

ステップ2の「Gitを初めからていねいに」をやる。

「みんなでつかう - push pull」より。

続きを読む

Gitに入門する -その9-

blog.takanabe.tokyo

ステップ2の「Gitを初めからていねいに」をやる。

「みんなでつかう - ベアリポジトリとクローン,リモートリポジトリ」より。

続きを読む

Gitに入門する -その8-

blog.takanabe.tokyo

ステップ2の「Gitを初めからていねいに」をやる。

「ひとりでつかう - 過去を改変」より。

続きを読む