怎样编译安装PHP5.3.*

2016年9月30日 | 分类: 【技术】

因为调试一个老程序,不得不降级。

实证:

1. 适用于php-5.2.17,但是因为http2.4.*不再支持php5.2.*,需要将Apache降级到 httpd-2.2.31。

2. 适用于php-5.3.*

下载:http://museum.php.net/php5/

编译安装php-5.2.17:

wget http://museum.php.net/php5/php-5.2.17.tar.gz && tar zxvf php-5.2.17.tar.gz && cd php-5.2.17
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache2/bin/apxs
make
make install

编译安装php-5.3.3:

wget http://museum.php.net/php5/php-5.3.3.tar.gz && tar zxvf php-5.3.3.tar.gz && cd php-5.3.3
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache2/bin/apxs
make ZEND_EXTRA_LIBS='-liconv'
make install

编译安装php-5.3.29:

wget http://museum.php.net/php5/php-5.3.29.tar.gz && tar zxvf php-5.3.29.tar.gz && cd php-5.3.29
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache2/bin/apxs
make ZEND_EXTRA_LIBS='-liconv'
make install

报错1:

make时报错:

...
/root/php-5.3.3/ext/dom/node.c: In function ‘dom_canonicalization’:
/root/php-5.3.3/ext/dom/node.c:1903:21: error: dereferencing pointer to incomplete type
    ret = buf->buffer->use;
                     ^
In file included from /root/php-5.3.3/main/php.h:38:0,
                 from /root/php-5.3.3/ext/dom/node.c:26:
/root/php-5.3.3/ext/dom/node.c:1905:40: error: dereferencing pointer to incomplete type
     RETVAL_STRINGL((char *) buf->buffer->content, ret, 1);
                                        ^
/root/php-5.3.3/Zend/zend_API.h:545:20: note: in definition of macro ‘ZVAL_STRINGL’
   const char *__s=(s); int __l=l;  \
                    ^
/root/php-5.3.3/ext/dom/node.c:1905:5: note: in expansion of macro ‘RETVAL_STRINGL’
     RETVAL_STRINGL((char *) buf->buffer->content, ret, 1);
     ^
make: *** [ext/dom/node.lo] Error 1

参考:http://blog.csdn.net/moqiang02/article/details/19699557

有一个补丁可以解决问题:

cd /root/php-5.3.3/
curl -o php-5.x.x.patch https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt
patch -p0 -b < php-5.x.x.patch

输出:

patching file ext/dom/node.c
Hunk #1 succeeded at 1900 (offset 5 lines).
patching file ext/dom/documenttype.c
patching file ext/simplexml/simplexml.c
Hunk #1 succeeded at 1385 (offset -32 lines).

然后重新make。

报错2:

make时报错:

...
ext/iconv/iconv.o: In function `php_iconv_stream_filter_dtor':
/root/php-5.3.3/ext/iconv/iconv.c:2440: undefined reference to `libiconv_close'
ext/iconv/iconv.o: In function `_php_iconv_appendl':
/root/php-5.3.3/ext/iconv/iconv.c:337: undefined reference to `libiconv'
/root/php-5.3.3/ext/iconv/iconv.c:374: undefined reference to `libiconv'
...
collect2: error: ld returned 1 exit status

参考:http://blog.csdn.net/21aspnet/article/details/6925644

编辑 Makefile ,在 81 行末尾添加 -liconv :

EXTRA_LIBS = -lcrypt -lresolv -lcrypt -lrt -lm -ldl -lnsl -lxml2 -lz -llzma -lm -ldl -lxml2 -lz -llzma -lm -ldl -lxml2 -lz -llzma -lm -ldl -lcrypt -lxml2 -lz -llzma -lm -ldl -lxml2 -lz -llzma -lm -ldl -lxml2 -lz -llzma -lm -ldl -lcrypt -liconv

然后重新make,顺利通过; make install,顺利编译完成。

创建软连接:

ln -s /usr/local/php/bin/php /usr/local/bin/
ln -s /usr/local/php/bin/phpize /usr/local/bin/
ln -s /usr/local/php/bin/php-config /usr/local/bin/

查看版本:

php -v

输出:

PHP 5.2.17 (cli) (built: Jan  8 2017 04:31:43)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies