最简单的LAMP环境搭建当然是通过yum来安装,但由于镜像仓库中的软件版本更新较慢,经常会遇到版本过旧的问题,尤其是安装一些新版本的CMS时的PHP。

这时我们需要手动编译PHP,Linux编译安装经常是./configure--make--make install三大步,但是实践中发现简单地这样安装会发现通过php -v呈现的版本号已经改变但是通过phpinfo()函数查看到的httpd使用的php版本还是没有改变。

回顾apache引入php支持的配置过程,其中最主要的是在httpd.conf中配置了LoadModule php5_module modules/libphp5.so,结合系统php已更新而apache中的php却未更新的现像,可以推测apache调用php并不是直接调用系统的php而就是调用libphp5.so;新编译安装php未成功替换掉apache中的php的原因就是没编译生成新的libphp5.so去替换旧的libphp5.so。

而最终的测试可以验证这种推测是正确的。以下是Apache升级PHP的步骤,这里有些操作比较粗操比如提示未知的编译选项--with-exec-dir等并未理会,生产环境按此升级需谨慎。

1.下载php

下载链接:http://php.net/downloads.php

选择需要版本下载,5.x版本和7.x版本还是有点区别的,建议原先是5.x的选择5.x版本下载7.x的版本选择7.x下载

2.安装apxs

apxs是apache扩展的编译程序,要确保apxs已安装

which apxs

如果不存在该命令则通过安装httpd-devel来安装:

装完后再次使用which命令定位apxs安装路径:

3.查看当前使用php编译参数

在apache网站根目录下写个phpinfo文件,然后在浏览器访问

cat > phpinfo.php << EOF
<?php
phpinfo();
?>
EOF

Configure Command右侧即当前PHP编译命令,我们使用一样的命令编译新的PHP即可(注意--with-apxs2的值是否上步安装的apxs所在的路径)

4.编译安装PHP

将压下载的PHP进入解压出的目录,使用./configure--make--make install三大步进行编译安装

./configure就直接复制上边查到的,单引号不影响的,有可能有些包没安装安装即可,有可能有些选项新版不支持这里我没管。如我这里使用:

'./configure' '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib64' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-xpm-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--with-kerberos' '--enable-ucd-snmp-hack' '--enable-shmop' '--enable-calendar' '--without-sqlite' '--with-libxml-dir=/usr' '--enable-xml' '--with-system-tzdata' '--with-apxs2=/usr/sbin/apxs' '--without-mysql' '--without-gd' '--disable-dom' '--disable-dba' '--without-unixODBC' '--disable-pdo' '--disable-xmlreader' '--disable-xmlwriter' '--without-sqlite3' '--disable-phar' '--disable-fileinfo' '--disable-json' '--without-pspell' '--disable-wddx' '--without-curl' '--disable-posix' '--disable-sysvmsg' '--disable-sysvshm' '--disable-sysvsem'

make

make install

configure报错:checking for BZip2 in default path... not found

解决办法:yum install -y gzip2-devel

configure报错:configure: error: Unable to locate gmp.h

解决办法:yum install -y gmp-devel

make报错:ext/pcre/.libs/php_pcre.o: In function `zm_info_pcre': /usr/myapp/php-5.6.30/ext/pcre/php_pcre.c:133: undefined reference to `php_pcre_version'....

解决办法:看意思是结构体没定义,可能是php_pcre.c没正确include但这可能性不大,也可能是安装的pcre版本太旧;不太清楚,最后我直接把./configure中的--with-pcre-regex=/usr去掉了,慎用。

5.再次查看phpinfo.php页面确认升级成功

先重启apache再刷新页面

service httpd restart

参考:

https://segmentfault.com/q/1010000005115503/a-1020000005116821

http://blog.csdn.net/work888study/article/details/8610467

Apache升级PHP教程(以5.3.3升级到5.6.30为例)的更多相关文章

  1. Apache Solr 初级教程(介绍、安装部署、Java接口、中文分词)

    Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...

  2. SQL 2008升级SQL 2008 R2完全教程或者10.00.1600升级10.50.1600

    http://blog.csdn.net/feng19821209/article/details/8571571 SQL 2008升级SQL 2008 R2完全教程或者10.00.1600升级10. ...

  3. CentOS6.0(64位)安装Apache+PHP+Mysql教程,安装Magento(解决DOM,Mcrypt,GD问题)完整教程

    CentOS6.0(64位)安装Apache+PHP+Mysql教程,安装Magento(解决DOM,Mcrypt,GD问题)完整教程 0   Posted by :小黑 On : 2012 年 9 ...

  4. SQL 2008升级SQL 2008 R2完全教程或者10.00.4000升级10.50.1600

    今天将由于需要就将我的SQL 2008升级到SQL 2008 R2. 说到为什么要升级是因为,从另一台机器上备份了一个数据库,到我的机器上还原的时候提示“System.Data.SqlClient.S ...

  5. Tips & Tricks:Apache log4j简明教程(二)

    在上一讲Apache log4j简明教程(一)中介绍了log4j的基本概念,配置文件,以及将日志写入文件的方法,并给出了一个详细的示例.这一讲,我在继续谈一谈如何使用log4j将日志写入MySQL数据 ...

  6. Tips & Tricks:Apache log4j简明教程(一)

    Apache log4j的官方介绍是“log4j is a reliable, fast and flexible logging framework (APIs) written in Java, ...

  7. Apache Solr入门教程(初学者之旅)

    Apache Solr入门教程(初学者之旅) 写在前面:本文涉及solr入门的各方面,建议边思考边实践,相信能帮助你对solr有个清晰全面的了解并能简单实用. 在Apache Solr初学者教程的这个 ...

  8. Apache Pig中文教程集合

    Apache Pig中文教程集合: http://www.codelast.com/?p=4550#more-4550

  9. python2.7.5升级到2.7.14或者直接升级到3.6.4

    python2.7.5升级到2.7.14 1.安装升级GCC yum install -y gcc* openssl openssl-devel ncurses-devel.x86_64  bzip2 ...

  10. Python—python2.7.5升级到2.7.14或者直接升级到3.6.4

    python2.7.5升级到2.7.14 1.安装升级GCC yum install -y gcc* openssl openssl-devel ncurses-devel.x86_64  bzip2 ...

随机推荐

  1. react native 渐变组件 react-native-linear-gradient

    github:  https://github.com/react-native-community/react-native-linear-gradient 安装:yarn add  react-n ...

  2. WebStorm破解方法

    http://www.jianshu.com/p/85266fa16639 http://idea.lanyus.com/ webstorm 入门指南 破解方法 1. 下载的WebStorm http ...

  3. [osgearth][原]仿照谷歌,修改oe漫游器中focal(视角切换)功能

    oe中的视角加速感觉好奇怪,就仿照谷歌方式去改了. 先看看oe原来的漫游器改变视角的接口: void CameraManipulator::setViewpoint(const Viewpoint&a ...

  4. 修改linux镜像

    修改镜像的常用命令有: guestfish,guestmount等. ●修改静态文件. 命令:guestfish 安装包:yum install -y guestfish ①mount镜像:guest ...

  5. ionic-input单选复选杂交

    <label class="toggle toggle-positive"> <input type="radio" ng-model=&qu ...

  6. 大数据-Hive 常用命令

    Hive 启动 ~$ hive 退出 hive>quit; --退出hive or hive> exit; --exit会影响之前的使用,所以需要下一句kill掉hadoop的进程 > ...

  7. 第 6 章 存储 - 043 - data-packed volume container

    data-packed volume container 将数据打包到镜像中,然后通过 docker managed volume 共享 1.先用Dockerfile 构建镜像 ADD 将静态文件添加 ...

  8. 基于 Spring Cloud 完整的微服务架构实战

    本项目是一个基于 Spring Boot.Spring Cloud.Spring Oauth2 和 Spring Cloud Netflix 等框架构建的微服务项目. @作者:Sheldon地址:ht ...

  9. English trip V1 - B 1. How much is it? 它是多少钱? Teacher:Corrine Key: is/are

    In this lesson you will learn to ask about prices. 本节课你将学习询问关于价格 课上内容(Lesson) one piece of     two p ...

  10. python2.x编码问题实例

    1,编码问题,主要是区分面向人类的字符串,面向计算机的字节序列 在python3中,字符串是str(默认即unicode),字节序列是bytes 在python2中,字符串是unicode,字节序列是 ...