一、先卸载旧版php
yum remove php* php-common
二、安装epel
yum -y install epel-release
三、安装第三方yum源
#centos 6.x 的yum源 (二选一) rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm #centos 7 的yum源 (二选一) rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
#查看是否安装了目标 yum 源 ls /etc/yum.repos.d # 输出 目标yum源的信息 cat webtatic.repo [webtatic] name=Webtatic Repository EL7 - $basearch #baseurl=https://repo.webtatic.com/yum/el7/$basearch/ mirrorlist=https://mirror.webtatic.com/yum/el7/$basearch/mirrorlist failovermethod=priority enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-el7 [webtatic-debuginfo] name=Webtatic Repository EL7 - $basearch - Debug #baseurl=https://repo.webtatic.com/yum/el7/$basearch/debug/ mirrorlist=https://mirror.webtatic.com/yum/el7/$basearch/debug/mirrorlist failovermethod=priority enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-el7 [webtatic-source] name=Webtatic Repository EL7 - $basearch - Source #baseurl=https://repo.webtatic.com/yum/el7/SRPMS/ mirrorlist=https://mirror.webtatic.com/yum/el7/SRPMS/mirrorlist failovermethod=priority enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-el7<br>
通过访问 https://repo.webtatic.com/yum/el7/SRPMS/
我们就能看到所有的 rpm 安装包了
#也可以通过命令查看该源对应的安装包 yum list --enablerepo=webtatic | grep php #或者 直接 搜索 相关安装包 yum search php71w Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.linode.com * epel: mirrors.kernel.org * extras: mirrors.linode.com * updates: mirrors.linode.com * webtatic: sp.repo.webtatic.com ============================= N/S matched: php71w ============================== mod_php71w.x86_64 : PHP module for the Apache HTTP Server php71w-bcmath.x86_64 : A module for PHP applications for using the bcmath : library php71w-cli.x86_64 : Command-line interface for PHP php71w-common.x86_64 : Common files for PHP
注意一个问题,php71w和php70w,它们的描述方式不同。 php70w.x86_64 : PHP scripting language for creating dynamic web sites mod_php71w.x86_64 : PHP module for the Apache HTTP Server 其实效果是一样的,就是php 服务器,注意啦。
yum search php70w Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.linode.com * epel: mirrors.kernel.org * extras: mirrors.linode.com * updates: mirrors.linode.com * webtatic: sp.repo.webtatic.com ============================= N/S matched: php70w ============================== php70w.x86_64 : PHP scripting language for creating dynamic web sites php70w-bcmath.x86_64 : A module for PHP applications for using the bcmath : library php70w-cli.x86_64 : Command-line interface for PHP php70w-common.x86_64 : Common files for PHP <br>
四、安装 PHP 7.1
# 安装php7.1 yum install php71w -y # nginx连接使用 yum install php71w-fpm -y # 宽字节 yum install php71w-mbstring -y # mysql相关 yum install php71w-mysqlnd -y # redis扩展 yum install php71w-pecl-redis -y # 加密使用 yum install php71w-mcrypt -y # 性能加速 php5.5 以上使用 yum install php71w-opcache -y # 安装这些基本的可以满足大量需求, 至于有些扩展, 会在安装这些库的时候附加进去<br>
五、启动 PHP 7.1
我已经安装好需要程序,要想PHP请求被Nginx接收并转交给PHP-FPM再由PHP解释器执行返回结果,还需要做一些配置。
1、设置Nginx
Nginx 配置文件中 已经配置过,如何接收 php请求了。
2、启动 PHP-FPM
# 启动PHP-FPM systemctl start php-fpm # 设置开机启动 systemctl enable php-fpm
六、基本配置优化
对于搭建一般的小网站,参考 wordpress-优化php-fpm和mysql 。