「Nginx, MySQL(MariaDB), PHP7をCentOS7にインストールしてVPS化する本」

スポンサーリンク

kindle本「Nginx, MySQL(MariaDB), PHP7をCentOS7にインストールしてVPS化する本」のまとめ。

点数

75

感想

LEMP環境を構築するうえで、必要最低限の情報が短くまとめられていた。
時間がない人には、役に立つ内容だと思う。

Nginxのインストール

デフォルトリポジトリにはNginxがないので、EPELを追加。
yum install -y epel-release
yum install -y nginx
systemctl start nginx
systemctl enable nginx

MySQL(MariaDB)のインストール

MariaDBはMySQLとほぼ完全な互換性を持つうえに実行速度が15%ほど速い。
MariaDBはCentOS7のリポジトリに含まれている。

yum install -y mariadb-server mariadb
systemctl start mariadb
systemctl enable mariadb
mysql_sequre_installation
rootパスワードを要求されるのでそのままEnterを押し、パスワードを設定する

PHP7.3またはPHP7.4のインストール

remiリポジトリを最新版に更新する必要がある。
※ remiはEPELに依存しているため、remiを使うときはEPELも必要。
wget http://rpms.remirepo.net/enterprise/remirelease7.rpm
rpm -Uvh remi-relase-7.rpm
yum install -y yum-utils # PHPリポジトリのインストールに必要
yum config-manager --enable remi-php-73 # デフォルトでは無効になっているphp73を有効にする
yum --enablerepo=remi,remi-php73 install php-fpm php-common # PHPのインストール
yum --enablerepo=remi,remiphp73 install php-opcache,php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml # PHPの一般的なモジュールをインストール

PHP7を動かすためのNginxの設定

vi /etc/nginx/conf.d/default.conf

server {
  listen  80;
  server_name IPアドレス;
  root  /usr/share/nginx/html;
  index index.php index.html index.htm; 
  location / {
    try_files $uri $uri/ =404;
  }
  error_page 404 /404.html;
  error_page 500 502 503 504 /50x.html; 
  location = /50x.html {
    root /usr/share/nginx/html;
  }
  location ~ .php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/phpfpm/phpfpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}

systemctl restart nginx

PHP-FPMの設定

vi /etc/phpfpm.d/www.conf

  • user=apacheuser=nginxに変更
  • group=apachegroup=nginxに変更
  • listen.owner=nobodylisten.owner=nginxに変更
  • listen.group=nobodylisten.group=nginxに変更
  • ;listen=127.0.0.1:9000の下にlisten=/var/run/phpfpm/phpfpm.sockを追加

systemctl start php-fpm
systemctl enable php-fpm

コメント