【CentOS】安装PHP、PHP-FPM和NginX
安装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的存储库中,存在两个版本,即稳定版和主线版。官方建议使用主线版,因此我们将添加主线存储库。
# vi /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