Apache升级PHP教程(以5.3.3升级到5.6.30为例)

时间:2022-05-12 00:14:38

最简单的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来安装:

Apache升级PHP教程(以5.3.3升级到5.6.30为例)

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

Apache升级PHP教程(以5.3.3升级到5.6.30为例)

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

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

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

Apache升级PHP教程(以5.3.3升级到5.6.30为例)

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

Apache升级PHP教程(以5.3.3升级到5.6.30为例)

参考:

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&period;00&period;1600升级10&period;50&period;1600

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

  3. CentOS6&period;0&lpar;64位&rpar;安装Apache&plus;PHP&plus;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&period;00&period;4000升级10&period;50&period;1600

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

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

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

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

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

  7. Apache Solr入门教程&lpar;初学者之旅&rpar;

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

  8. Apache Pig中文教程集合

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

  9. python2&period;7&period;5升级到2&period;7&period;14或者直接升级到3&period;6&period;4

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

  10. Python—python2&period;7&period;5升级到2&period;7&period;14或者直接升级到3&period;6&period;4

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

随机推荐

  1. IOS中div contenteditable&equals;true无法输入

    在IOS中<div contenteditable="true"></div>中点击时可以弹出键盘但是无法输入.加一个样式-webkit-user-sele ...

  2. HDU 3584 Cube (三维 树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3584 Cube Problem Description Given an N*N*N cube A,  ...

  3. Django&plus;python&plus;BeautifulSoup垂直搜索爬虫

    http://blog.sina.com.cn/s/blog_709475a10100wmln.html

  4. uC&sol;OS-II之系统函数20160526

    任务管理 1 OSTaskCreate() 建立一个新任务.任务的建立可以在多任务环境启动之前,也可以在正在运行的任务中建立.中断处理程序中不能 建立任务.一个任务可以为无限循环的结构. 函数原型:I ...

  5. crystal report format number

    ToText({#totalPrice}, 2,'.', ',')  &" €" http://crystaltricks.com/wordpress/?p=149

  6. 一个简单的多线程Python爬虫(一)

    一个简单的多线程Python爬虫 最近想要抓取拉勾网的数据,最开始是使用Scrapy的,但是遇到了下面两个问题: 前端页面是用JS模板引擎生成的 接口主要是用POST提交参数的 目前不会处理使用JS模 ...

  7. 【转】ActionBar的基本用法

    原文网址:http://irtutsk.iteye.com/blog/2117707 ActionBar的组成: [1]AppIcon:标题区,显示应用程序图标和标题,也可以自定义. [2]ViewC ...

  8. POJ2241——The Tower of Babylon

    The Tower of Babylon Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2207   Accepted: 1 ...

  9. HDU1789Doing Homework again(贪婪)

    HDU1789Doing Homework again(贪心) 题目链接 题目大意:给你n们作业的最后期限和过了这个期限没做须要扣的分数.问如何安排能够使得扣分最少. 解题思路:贪心,将扣分多的作业排 ...

  10. wordpress学习(三)-----add&lowbar;action动作钩子和add&lowbar;filter&lpar;&rpar;过滤器钩子

    <?php echo "<h2>高级教程add_action动作和add_filter()过滤器</h2><br/>"; //1.学会使用 ...