需求:安装php5.6、php7


 

centos6 默认yum安装的版本是5.3.3-49  


centos7 默认yum安装的版本是5.4.16  


 

方案一:添加remi源

CentOS 6添加epel及remi源。

 

 rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm

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

 

CentOS 7添加epel及remi源。

 

# yum install epel-release

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

 


使用yum list命令查看可安装的包(Packege)。—–选配–可以看到能安装php7.0 、7.1



# yum list –enablerepo=remi –enablerepo=remi-php56 | grep php


 


yum源配置好了,下一步就安装PHP5.6。

centos6、7这样安装


安装PHP56

&nbsp;&nbsp;<span style="background-color: inherit;">yum</span> -y <span style="background-color: inherit;">install</span> --enablerepo=remi --enablerepo=remi-php56 php <span style="background-color: inherit;">php-fpm&nbsp;&nbsp;</span><span style="background-color: inherit;">php-gd&nbsp;php-mysql php-xml &nbsp;</span>php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug <span style="background-color: inherit;">php-pecl-xhprof</span>



如果安装PHP71


<span style="background-color: inherit;">yum</span> -y <span style="background-color: inherit;">install</span> --enablerepo=<span style="background-color: inherit;">remi-php71</span><span style="background-color: inherit;"> --enablerepo=remi-php71 php <span style="background-color: inherit;">php-fpm&nbsp;&nbsp;</span><span style="background-color: inherit;">php-gd&nbsp;php-mysql php-xml<span style="background-color: inherit;">&nbsp; </span></span>php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug</span>

 
方案二:添加webtatic

 

https://webtatic.com/packages/php56/
CentOS 7.x:
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

 
CentOS6.x:
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

 
安装php56

yum  install php56w php56w-fpm  php56w-gd php56w-mysql php56w-xml  php56w-opcache php56w-devel php56w-mbstring php56w-mcrypt php56w-mysql php56w-pecl-xdebug 

 
安装php71

 yum  install php71w php71w-fpm  php71w-gd php71w-mysql php71w-xml  php71w-opcache php71w-devel php71w-mbstring php71w-mcrypt php71w-mysql php71w-pecl-xdebug 

 
you can upgrade PHP by:









yum install yum-plugin-replace
 
yum replace php-common –replace-with=php71w-common



 


用PHP命令查看版本。



# php –version



 




 chkconfig –level 345 php-fpm on 

    <div style="background-color: inherit;">
        &nbsp;
    </div>

    <div style="background-color: inherit;">
        <div style="background-color: inherit;">
            systemctl&nbsp;restart&nbsp;&nbsp;php-fpm.service
        </div>
    </div>

    <div style="background-color: inherit;">
        <div style="background-color: inherit;">
            service&nbsp;php-fpm&nbsp;restart
        </div>
    </div>
</div>