LoginSignup
4
3

More than 3 years have passed since last update.

【CentOS】PHP、PHP-FPM、NginX のインストール

Last updated at Posted at 2019-02-08

PHP(7.2) のインストール

EPEL リポジトリの追加

# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Remi リポジトリの追加

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

リポジトリの確認

# ls -l /etc/yum.repos.d/

-rw-r--r--. 1 root root 1664 11月 23 22:16 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 11月 23 22:16 CentOS-CR.repo
-rw-r--r--. 1 root root  649 11月 23 22:16 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  630 11月 23 22:16 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 11月 23 22:16 CentOS-Sources.repo
-rw-r--r--. 1 root root 5701 11月 23 22:16 CentOS-Vault.repo
-rw-r--r--. 1 root root  314 11月 23 22:16 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 1050 10月  3  2017 epel-testing.repo
-rw-r--r--. 1 root root  951 10月  3  2017 epel.repo
-rw-r--r--. 1 root root  446 12月 22 02:50 remi-glpi91.repo
-rw-r--r--. 1 root root  446 12月 22 02:50 remi-glpi92.repo
-rw-r--r--. 1 root root  446 12月 22 02:50 remi-glpi93.repo
-rw-r--r--. 1 root root  446 12月 22 02:50 remi-glpi94.repo
-rw-r--r--. 1 root root  456 12月 22 02:50 remi-php54.repo
-rw-r--r--. 1 root root 1314 12月 22 02:50 remi-php70.repo
-rw-r--r--. 1 root root 1314 12月 22 02:50 remi-php71.repo
-rw-r--r--. 1 root root 1314 12月 22 02:50 remi-php72.repo
-rw-r--r--. 1 root root 1314 12月 22 02:50 remi-php73.repo
-rw-r--r--. 1 root root  750 12月 22 02:50 remi-safe.repo
-rw-r--r--. 1 root root 2605 12月 22 02:50 remi.repo

リポジトリを指定してインストール

# yum -y install --enablerepo=remi-php72 php

必要なパッケージがあれば php に続けて記入する。

インストールしたPHP、PHPパッケージを確認

# rpm -qa | grep php

php-pecl-mcrypt-1.0.2-1.el7.remi.7.2.x86_64
php-7.2.14-1.el7.remi.x86_64
php-json-7.2.14-1.el7.remi.x86_64
php-cli-7.2.14-1.el7.remi.x86_64
php-devel-7.2.14-1.el7.remi.x86_64
php-xml-7.2.14-1.el7.remi.x86_64
php-pdo-7.2.14-1.el7.remi.x86_64
php-fpm-7.2.14-1.el7.remi.x86_64
php-common-7.2.14-1.el7.remi.x86_64
php-gd-7.2.14-1.el7.remi.x86_64
php-mbstring-7.2.14-1.el7.remi.x86_64

PHP-FPM のインストール

PHP と同じリポジトリを指定してインストール

--enablerepo=remi-php72.repo でインストールした PHP と同じバージョンのリポジトリを指定しないとエラーが発生する場合があります。

PHP-FPM のインストール
# yum -y install --enablerepo=remi-php72 php-fpm

PHP-FPM の起動
# systemctl start php-fpm

PHP-FPM の自動起動化
# systemctl enable php-fpm

Nginx のインストール

リポジトリの追加

Nginx のリポジトリには stable と mainline 2つが存在します。
公式は mainline を推奨していますので mainline リポジトリを追加します。

# vi /etc/yum.repos.d/nginx.repo

リポジトリの内容を確認

/etc/yum.repos.d/nginx.repo
[nginx]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key

リポジトリを指定してインストール

Nginx をインストール
# yum -y install nginx --enablerepo=nginx

Nginx の起動
# systemctl start nginx

Nginx の自動起動化
# systemctl enable nginx
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3