PHP
Emacs
nginx
PostgreSQL

CentOS 7.3に最新のnginx+PHP7.1+PostgreSQL9.6環境作るメモ

個人的なメモです。本当に。
  • Webサーバを動かすユーザをpoeとします。(他のユーザ名の場合適宜poeを置き換えてください。)

  • 言わずもがな

sudo yum -y install emacs

sudo yum -y install git

ぺちぺーとえんじんえっくす

  • nginxのレポジトリを追加

sudo emacs /etc/yum.repos.d/nginx.repo

nginx.repo
[nginx]
name = nginx repo
baseurl = http://nginx.org/packages/centos/7/$basearch/
gpgcheck = 0
enabled = 1
  • epelレポジトリを追加

wget http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/7/x86_64/e/epel-release-7-10.noarch.rpm

sudo rpm -ivh epel-release-7-10.noarch.rpm

sudo yum -y update epel-release

  • remiレポジトリを追加

wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

sudo rpm -ivh remi-release-7.rpm

sudo yum -y update remi-release

  • ぺちぺー 7.1

sudo yum -y --enablerepo=remi-php71,epel install php-fpm php-gd php-gmp php-mbstring php-mcrypt php-opcache php-pdo php-pear-MDB2-Driver-mysqli php-pecl-memcached php-pecl-msgpack php-xml php-pgsql

  • php.iniの編集

sudo emacs /etc/php.ini

[emacs]C-s date.timezone

php.ini
date.timezone = "Asia/Tokyo"

sudo emacs /etc/php-fpm.d/www.conf

[emacs]M-g g 24

www.conf
user = poe
;comment....
group = poe

[emacs]M-g g 38

listen = /var/run/php-fpm/php-fpm.sock

[emacs]M-g g 48

www.conf
listen.owner = poe
listen.group = poe
listen.mode = 0660
  • nginx(たぶん1.12.1)

sudo yum -y --enablerepo=nginx install nginx

sudo emacs /etc/nginx/nginx.conf

nginx.conf
user poe;
  • default.confの編集

sudo emacs /etc/nginx/conf.d/default.conf

[emacs]M-g g 30

default.conf
location ~ \.php$ {
    root          /usr/share/nginx/html;
    fastcgi_pass  unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include       fastcgi_params;
}
  • php-fpmとnginxの起動とenable

sudo systemctl start php-fpm.service

sudo systemctl start nginx.service

sudo systemctl enable php-fpm.service

sudo systemctl enable nginx.service

DB(PostgreSQL)

  • リポジトリ追加

wget https://yum.postgresql.org/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm

sudo rpm -ivh pgdg-centos96-9.6-3.noarch.rpm

sudo yum -y update

  • インストール

sudo yum -y install postgresql96-server postgresql96-devel postgresql96-contrib

sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb

sudo passwd postgres

  • PostgreSQLの起動とenable

sudo systemctl start postgresql-9.6

sudo systemctl enable postgresql-9.6

  • 設定編集

sudo emacs /var/lib/pgsql/9.6/data/postgresql.conf

[emacs]M-g g 59

postgresql.conf
listen_address = '*'

[emacs]M-g g 431

postgresql.conf
log_line_prefix = '<%u:%d %t>'

sudo emacs /var/lib/pgsql/9.6/data/pg_hba.conf

[emacs]M-g g 80

pg_hba.conf
#comment....
local   all     all             trust
#comment....
host    all     127.0.0.1/32    trust
#comment....
host    all     ::1/128         trust
  • 再起動

sudo systemctl restart postgresql-9.6

  • firewall-cmdで開ける

sudo firewall-cmd --permanent --zone=public --add-service=postgresql

sudo systemctl restart firewalld.service

  • システムリブートしとく

sudo reboot


いじょ。
参考:
CentOS7にpostgresql9.6をセットアップ