docker上のAmazon Linuxへのanyenv + php7.1.2 + Symfony3.2のインストールメモ


docker

ホストPCでの操作

$ docker images
$ docker run -i -t amazonlinux:2016.09 /bin/bash

OS + ssh

# yum update -y
# yum install -y vim zsh git wget curl tmux bzip2 sudo openssh-server openssh passwd
# echo "NETWORKING=yes" >/etc/sysconfig/network
# /etc/init.d/sshd start

yum

東京リージョンに変更する

vim /etc/yum/vars/awsregion

ap-northeast-1

nginx

# yum install -y nginx

vim /etc/nginx/conf.d/default.conf

/etc/nginx/conf.d/default.conf
server {
  listen "8071";
  root /var/www/hoge/web;
  location ~ \.php.*$ {
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_pass 127.0.0.1:7100;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    include fastcgi_params;
  }
}

user

# useradd -g nginx -s /bin/bash www
# echo "www ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/www
# su - www
$ mkdir .ssh
$ chmod 700 .ssh
$ echo "公開鍵" > ~/.ssh/authorized_keys
$ chmod 600 .ssh/authorized_keys

dockerコミット

ホストPC上での操作

$ docker ps -a
$ docker commit ハッシュ値 symfony3
$ docker run -it -p 8071:8071 -p 10022:22 symfony3 /bin/bash

ssh

ホストPCからssh

$ ssh -p 10022 -i ~/.ssh/id_rsa www@localhost

anyenv

$ git clone https://github.com/riywo/anyenv ~/.anyenv
$ echo 'export PATH="$HOME/.anyenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(anyenv init -)"' >> ~/.bash_profile
$ exec $SHELL -l
$ cd ~
$ mkdir -p $(anyenv root)/plugins
$ git clone https://github.com/znz/anyenv-update.git $(anyenv root)/plugins/anyenv-update
$ anyenv install phpenv
$ exec $SHELL -l

PHP

必要なコンパイラ、ライブラリのインストール

$ sudo yum install -y gcc gcc-c++ libgcc cmake ncurses-devel re2c autoconf automake bison libxml2 libxml2-devel openssl-devel curl-devel libpng libpng-devel libmcrypt libmcrypt-devel readline-devel libtidy libtidy-devel libxslt libxslt-devel zlib-devel libjpeg-turbo libjpeg-turbo-devel libcurl-devel libicu-devel freetype freetype-devel

intlに必要なicuのインストール

$ wget http://download.icu-project.org/files/icu4c/57.1/icu4c-57_1-src.tgz
$ tar xvzf icu4c-57_1-src.tgz
$ cd ./icu/source
$ ./configure --prefix=/opt/icu
$ make
$ sudo make install

ライブラリの設定

$ sudo vim /etc/ld.so.conf
/etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib
/usr/lib64
sudo ldconfig

php-buildのオプション追加

vim ~/.anyenv/envs/phpenv/plugins/php-build/share/php-build/default_configure_options

~/.anyenv/envs/phpenv/plugins/php-build/share/php-build/default_configure_options
--enable-mbregex
--enable-gd-native-ttf
--with-freetype-dir=/usr/local/
--with-libdir=lib
--enable-intl
--with-icu-dir=/opt/icu

phpのインストール

$ phpenv install 7.1.2
$ phpenv global 7.1.2
$ exec $SHELL -l

phpの設定

vim ~/.anyenv/envs/phpenv/versions/7.1.2/etc/php.ini

~/.anyenv/envs/phpenv/versions/7.1.2/etc/php.ini
date.timezone = Asia/Tokyo

PHP-FPMの設定

$ cp ~/.anyenv/envs/phpenv/versions/7.1.2/etc/php-fpm.d/www.conf.default ~/.anyenv/envs/phpenv/versions/7.1.2/etc/php-fpm.conf

vim ~/.anyenv/envs/phpenv/versions/7.1.2/etc/php-fpm.conf

~/.anyenv/envs/phpenv/versions/7.1.2/etc/php-fpm.conf
listen = 127.0.0.1:7100
listen.allowed_clients = 127.0.0.1
pm = ondemand
pm.max_children = 5
user = www
group = nginx

php-fpm起動

$ sudo ~/.anyenv/envs/phpenv/versions/7.1.2/sbin/php-fpm

nginx起動

$ sudo /etc/init.d/nginx start

Symfony3

$ sudo mkdir -p /var/www
$ cd /var/www
$ composer create-project symfony/framework-standard-edition hoge "3.2.*"

参考文献