Posted at

EC2にすばやくnginx+PHP56+mysql56の環境を作る

More than 3 years have passed since last update.


基本設定

これをやる


nginxをいれる

sudo yum install -y nginx


設定

sudo vim /etc/nginx/nginx.conf

location ~ \.php$ {

if (!-f $document_root$fastcgi_script_name) {
return 404;
}

fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;

include fastcgi_params;
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;
}

sudo vim /etc/nginx/conf.d/php-fpm.conf-5.6

upstream php-fpm {

server unix:/var/run/php-fpm.sock;
}


PHPとエクステンションをいれる

sudo yum install -y nginx php56 php56-fpm php56-mbstring php56-mysqlnd php56-gd php56-pdo


確認

php -v

PHP 5.6.24 (cli) (built: Jul 28 2016 22:15:42) 

Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies


FPM設定

sudo vim /etc/php-fpm-5.6.d/www.conf

user = myuser

group = myuser
listen = /var/run/php-fpm.sock
listen.owner = myuser
listen.group = myuser
listen.mode = 0666
catch_workers_output = yes


mysqlをいれる

sudo yum install -y mysql56 mysql56-server


セキュリティ設定

mysql_secure_installation を実行して各種設定を行う


自動起動設定

chkconfig nginx on

chkconfig mysqld on
chkconfig php-fpm on


確認

chkconfig --list nginx

chkconfig --list mysqld
chkconfig --list php-fpm


起動

sudo service nginx start

sudo service mysqld start

sudo service php-fpm start

こんな感じで完成。