CentOS 6.5 安装最新版本的php

Centos下Yum安装PHP5.5,5.6,7.0

默认的版本太低了,手动安装有一些麻烦,想采用Yum安装的可以使用下面的方案:
1.检查当前安装的PHP包
yum  list installed | grep php
如果有安装的PHP包,先删除他们
 yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php- mysql.x86_64 php-pdo.x86_64
2.Centos 5.X
  rpm -Uvh http: // mirror.webtatic.com/yum/el5/latest.rpm
  CentOs 6.x
  rpm -Uvh http: // mirror.webtatic.com/yum/el6/latest.rpm
  CentOs 7.X
rpm -Uvh https: // mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https: // mirror.webtatic.com/yum/el7/webtatic-release.rpm
如果想删除上面安装的包,重新安装
rpm -qa | grep webstatic
rpm -e  上面搜索到的包即可

3.运行yum install
   yum install php55w . x86_64 php55w - cli . x86_64 php55w - common . x86_64 php55w - gd . x86_64 php55w - ldap . x86_64 php55w - mbstring . x86_64 php55w - mcrypt . x86_64 php55w - mysql . x86_64 php55w - pdo . x86_64

yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64

注:如果想升级到5.6把上面的55w换成56w就可以了。

yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64
4.安装PHP FPM
yum install php55w-fpm 
yum install php56w-fpm 
yum install php70w-fpm

注:如果想升级到5.6把上面的55w换成56w就可以了。


原文地址   http://www.blogjava.net/nkjava/archive/2015/01/20/422289.html


我参考的是另外一篇博文

 

Centos 6.x/7.x yum安装php5.6.X(最新版)



鉴于Centos 默认yum源的php版本太低了,手动编译安装又有点一些麻烦,那么如何采用Yum安装的方案安装最新版呢。那么,今天我们就来学习下如何用yum安装php最新版。


1.检查当前安装的PHP包
[plain]  view plain  copy
  1. yum list installed | grep php  


如果有安装的PHP包,先删除他们

[html]  view plain  copy
  1. yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64  


配置yum源

追加CentOS 6.5的epel及remi源。

?
1
2
# 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.0的源。

?
1
2
# yum install epel-release
# rpm -ivh http: //rpms.famillecollet.com/enterprise/remi-release-7.rpm

使用yum list命令查看可安装的包(Packege)。

?
1
# yum list --enablerepo=remi --enablerepo=remi-php56 | grep php

安装PHP5.6.x

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

?
1
# yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof

PHP命令查看版本。

?
1
2
3
4
5
6
# php --version
PHP 5.6.0 (cli) (built: Sep  3 2014 19:51:31)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
     with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
     with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

安装PHP-fpm

[html]  view plain  copy
  1. yum install --enablerepo=remi --enablerepo=remi-php56 php-fpm  



在这里安装的版本是PHP5.6.13。

从PHP5.5开始PHP代码缓存从APC变成了Zend OPcache了。


其他源:

2.Centos 5.X
  rpm -Uvh http: // mirror.webtatic.com/yum/el5/latest.rpm
  CentOs 6.x
  rpm -Uvh http: // mirror.webtatic.com/yum/el6/latest.rpm
  CentOs 7.X
rpm -Uvh https: // mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https: // mirror.webtatic.com/yum/el7/webtatic-release.rpm
如果想删除上面安装的包,重新安装
rpm -qa | grep webstatic
rpm -e  上面搜索到的包即可

3.运行yum install
   yum install php55w . x86_64 php55w - cli . x86_64 php55w - common . x86_64 php55w - gd . x86_64 php55w - ldap . x86_64 php55w - mbstring . x86_64 php55w - mcrypt . x86_64 php55w - mysql . x86_64 php55w - pdo . x86_64

yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64

注:如果想升级到5.6把上面的55w换成56w就可以了。
4.安装PHP FPM
yum install php55w-fpm
注:如果想升级到5.6把上面的55w换成56w就可以了。



成功在望:测试 PHP

最后,让我们来测试下 nginx 是否能处理 PHP 页面。在测试之前,请确保重启 nginx 和 PHP-FPM。

在 CentOS 7 系统上:

<ol class="linenums" style="margin-left: 55px; padding: 5px 0px; color: rgb(92, 92, 92); word-wrap: break-word; word-break: normal; border: none; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; background: rgb(247, 247, 247);"><li class="L0" style="list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="pln" style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">$ sudo systemctl restart nginx</span></li><li class="L1" style="list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="pln" style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">$ sudo systemctl restart php</span><span class="pun" style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">-</span><span class="pln" style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">fpm </span></li></ol>

在 CentOS 6 系统上:

<ol class="linenums" style="margin-left: 55px; padding: 5px 0px; color: rgb(92, 92, 92); word-wrap: break-word; word-break: normal; border: none; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; background: rgb(247, 247, 247);"><li class="L0" style="list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="pln" style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">$ sudo service nginx restart</span></li><li class="L1" style="list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="pln" style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">$ sudo service php</span><span class="pun" style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">-</span><span class="pln" style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">fpm restart </span></li></ol>

创建一个叫名叫 test.php 的文件,然后写入如下内容,并放入 /var/www/html/ 目录。

<ol class="linenums" style="margin-left: 55px; padding: 5px 0px; color: rgb(92, 92, 92); word-wrap: break-word; word-break: normal; border: none; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; background: rgb(247, 247, 247);"><li class="L0" style="list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="pun" style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><?</span><span class="pln" style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">php phpinfo</span><span class="pun" style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">();</span><span class="pln" style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">?></span></li></ol>

打开浏览器,输入 http://nginx的IP地址/test.php 。

如果您能看到如上所示的页面,说明设置的 LEMP 完全成功!

地址 http://blog.csdn.net/zhaozuosui/article/details/48394409

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值