php.jpg
php.jpg

因为 typecho 的测试版 appstore 需要使用 curl 访问 https,这个 DO 主机是 15 年部署的,当时编译 php 时候没有考虑为 curl 增加对 https 的支持。因此打算更新 php 顺便将 curl 也更新了。网上教程很多,随便搜索一下都有很多。我这里就将过程中遇到的几个梗吐槽一下,希望也遇到相似情况的朋友可以少走点弯路。

这个主机是基于 De­bian 7,web 架构是 ng­inx + php (相关操作仅供指引请尽量备份好相关数据),本文是通过编译方式升级 php。

准备工作
通过命令行查看 PHP 编译信息

php -i | grep configure

得到我的主机的 php 编译信息是这样的

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl=/usr --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --enable-xml --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --disable-ipv6 --without-pear --with-iconv=/usr/local/lib --disable-debug --enable-opcache

下载好新版的 php 并解压

wget http://php.net/distributions/php-5.6.30.tar.gz
tar -zxvf php-5.6.30.tar.gz
cd php-5.6.30

备份好原来的 php 防止编译失败可以直接回滚

mv /usr/local/php  /usr/local/php5.3.8

进行./configure 时遇到了第一个梗
如果你不想看编译 curl 的过程,可以直接跳到梗 2 看解决办法。
con­fig­ure 就直接报错,提示类似下面的

checking for CURL support... yes
checking for CURL in default path... found in /usr
checking for cURL 7.9.8 or greater... libcurl 7.21.6
checking for curl_easy_perform in -lcurl... no
configure: error: There is something wrong. Please check config.log for more information.

搜索了下说 curl 版本不对,遂直接下载最新的 curl,通过编译(./con­fig­ure;make && make in­stall)方式升级了 curl。重新在 php 编译目录执行 con­fig­ure, 结果依旧上面的报错。

通过命令行 curl -V 查看 curl 版本如下

localhost:~ user$ curl -V
curl 7.52.1 (i686-pc-linux-gnu) libcurl/7.21.6

晕死,怎么 curl 和 libu­curl 的版本不一致的?爬文了半天没有结果。重装了 curl 几遍还没有结果。后来看了下 curl 的文档,发现是因为共享库造成的。晕死,curl 编译的配置应该是用./configure -disable-shared 才对。这样编译出来的 curl 和 libcurl 版本才是一致的。通过这样编译后 curl -V 得到的信息是这样的:

localhost:~ user$ curl -V
curl 7.52.1 (i686-pc-linux-gnu) libcurl/7.52.1

梗 2
重新在 php 编译目录执行 con­fig­ure, 结果依旧上面的报错()。上面编译 curl 的努力不是白费了吗?晕死。。。继续爬文,最后在 stackoverflow 找到解决问题的方法:重新安装 curl-de­vel 或者需要指定 curl 的安装路径(这个仅适合编译方式安装的 curl)

Ubuntu:

sudo apt-get install libcurl4-gnutls-dev

Cen­tOS:

sudo yum install curl-devel

编译方式安装了 curl 的(我的那种情况):
在 php 的 con­fig­ure 里面加入 --with-curl=/usr/local. (/usr/​lo­cal 为你 curl 安装的路径).

安装完之后,可以到 php 目录顺利 con­fig­ure 了。

准备 make, 梗三出现了
提示 iconv 函数不支持。晕死,我之前的 php 也是编译方式安装的,这个参数也是那样编译出来的。爬文。。。找到两个处理方法,直接在 con­fig­ure 参数里面删除 iconv,这样就无法使用 iconv。

因此我选择了另外一个方法。通过打开 php 安装目录的 Make­file,搜索到 EXTRA_LIBS =

-lcrypt -lz -lcrypt -lrt -lmysqlclient -lmcrypt -lltdl -lpng -lz -ljpeg -lcurl -lz -lrt -lm -ldl -lnsl -lrt -lxml2 -lssl -lcrypto -lcurl -lssh2 -lssl -lcrypto -lldap -lz -lrt -lxml2 -lfreetype -lz -lpng16 -lmysqlclient -lm -lrt -ldl -lxml2 -lcrypt -lxml2 -lxml2 -lxml2 -lxml2 -lcrypt

的后面增加 -liconv

然后重新 make,然后 make in­stall,ok 了。

弄完后,可以将原来在 /usr/​lo­cal/​php/​etc/ 备份的 php.ini 和 php-fpm.ini 恢复到当前位置。重启 php-fpm 即可。
查看 curl 版本,最新的!

curl.png
curl.png

-EOF-