Amazon Linuxへ php7.1.2 + Symfony3.2 + New Relic Servers/APMのインストールメモ

  • 3
    Like
  • 1
    Comment

New Relicはサインイン済の前提

必要に応じて

$ sudo yum update -y
$ sudo yum install -y vim zsh git wget curl tmux bzip2

NGINX

$ sudo yum install -y nginx

sudoedit /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 unix:/var/run/php-fpm.sock;
    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

$ sudo useradd -g nginx -s /bin/bash www

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/58.2/icu4c-58_2-src.tgz
$ tar xvzf icu4c-58_2-src.tgz
$ cd ./icu/source
$ ./configure --prefix=/opt/icu
$ make
$ sudo make install

ライブラリの設定

sudoedit /etc/ld.so.conf

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

phpのインストール

$ wget -O php-7.1.2.tar.gz http://jp2.php.net/get/php-7.1.2.tar.gz/from/this/mirror
$ tar xvzf php-7.1.2.tar.gz
$ cd php-7.1.2
$ ./configure \
--without-pear \
--with-gd \
--enable-sockets \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--enable-exif \
--enable-zip \
--with-zlib \
--with-zlib-dir=/usr \
--with-kerberos \
--with-openssl \
--with-mcrypt=/usr \
--enable-soap \
--enable-xmlreader \
--with-xsl \
--enable-ftp \
--enable-cgi \
--with-curl=/usr \
--with-tidy \
--with-xmlrpc \
--enable-sysvsem \
--enable-sysvshm \
--enable-shmop \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-pdo-sqlite \
--enable-pcntl \
--with-readline \
--enable-mbstring \
--disable-debug \
--enable-fpm \
--enable-bcmath \
--enable-phpdbg \
--enable-mbregex \
--enable-gd-native-ttf \
--with-freetype-dir=/usr/local/ \
--with-libdir=lib \
--enable-intl \
--with-icu-dir=/opt/icu \
--with-config-file-path=/etc/ \
--with-config-file-scan-dir=/etc/php.d
$ make
$ sudo make install
$ sudo cp ./php.ini-production /etc/php.ini
$ sudo cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
$ sudo chmod 755 /etc/init.d/php-fpm
$ sudo cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.conf

phpの設定

sudoedit /etc/php.ini

/etc/php.ini
date.timezone = Asia/Tokyo
[opcache]
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.max_wasted_percentage=5

PHP-FPMの設定

sudoedit /usr/local/etc/php-fpm.conf

/usr/local/etc/php-fpm.conf
listen = /var/run/php-fpm.sock
pm = ondemand
pm.max_children = 5
user = www
group = nginx
listen.owner = www
listen.group = nginx

composer

$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
$ sudo /usr/local/bin/php composer-setup.php --install-dir=/usr/local/bin --filename=composer
$ php -r "unlink('composer-setup.php');"

New Relic

Servers

$ sudo rpm -Uvh http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm
$ sudo yum -y install newrelic-sysmond
$ sudo nrsysmond-config --set license_key="ライセンスキー"
$ sudo /etc/init.d/newrelic-sysmond start

APM

$ sudo yum install newrelic-php5
$ sudo newrelic-install

インタラクティブモードでライセンスキーを登録する

sudoedit /etc/php.d/newrelic.ini

/etc/php.d/newrelic.ini
newrelic.enabled=true
newrelic.appname="symfony3"
newrelic.framework="symfony2"
newrelic.transaction_tracer.detail=1

Symfony3

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

php-fpm起動

$ sudo /etc/init.d/php-fpm start

nginx起動

$ sudo /etc/init.d/nginx start

New Relic SERVERS

nrs.png

New Relic APM

nrapm1.png

nrapm2.png