从git仓库下载代码,这样可以随时切换不同的PHP版本
1. git clone http://git.php.net/repository/php-src.git
2. cd php-src
3. git checkout PHP-5.5
4. 安装编译所需要的各种开发工具 sudo yum groupinstall 'Development Tools' 或者 yum install gcc gcc-c++ make openssl-devel libxml2 libxml2-devel
5. 构建 ./buildconf --force
6. 编译 './configigure --prefix=/etc/php55 --enable-debug --enable-maintainer-zts' prefix指定PHP的安装路径,可改为你自己的, 开启调试模式和下次线程安全
7. make
8. make install
9. 更改环境变量 vim /etc/profile 加入 PATH=$PATH:/etc/php55/bin; SOURCE PATH;
10. 执行'php --ini'查看是否成功, 发现没有ini配置文件,执行'cp php.ini-development /etc/php55/lib/php.ini'
在Redhat 7上编译安装PHP的时候,遇到了不支持bison的问题
Error Message: checking for bison... bison -y
checking for bison version... invalid
configure: WARNING: bison versions supported for regeneration of the Zend/PHP parsers: 1.28 1.35 1.75 1.875 2.0 2.1 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.5.1 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.7 (found 3.0).
在bugs.php.net找到了答案,最后发现只有PHP7才开始支持bison 3.0版本,以下是官网的解释
When building directly from Git sources or after custom modifications you might also need:
autoconf: 2.13+ (for PHP < 5.4.0), 2.59+ (for PHP >= 5.4.0)
automake: 1.4+
libtool: 1.4.x+ (except 1.4.2)
re2c: Version 0.13.4 or newer
flex: Version 2.5.4 (for PHP <= 5.2)
bison:
PHP 5.4: 1.28, 1.35, 1.75, 1.875, 2.0, 2.1, 2.2, 2.3, 2.4, 2.4.1, 2.4.2, 2.4.3, 2.5, 2.5.1, 2.6, 2.6.1, 2.6.2, 2.6.4
PHP 5.5: 2.4, 2.4.1, 2.4.2, 2.4.3, 2.5, 2.5.1, 2.6, 2.6.1, 2.6.2, 2.6.3, 2.6.4, 2.6.5, 2.7
PHP 5.6: >= 2.4, < 3.0
PHP 7.0: 2.4 or later (including Bison 3.x)
解决方案
- 卸载yum安装的bison,
sudo yum remove bison
- 下载2.6.4版本并编译安装
wget http://ftp.gnu.org/gnu/bison/bison-2.6.4.tar.gz
tar -xvzf bison-2.6.4.tar.gz
cd bison-2.6.4
./configure
make && make install
- 更改环境变量
vim /etc/environment
PATH=$PATH:/usr/local/bin
export PATH
- 使环境变量生效:
source /etc/environment
, 运行bison -V
查看bison版本
参考
http://www.phpinternalsbook.com/build_system/building_php.html#why-not-use-packages
https://bugs.php.net/bug.php?id=69055
http://php.net/manual/en/install.unix.php
https://github.com/php-build/php-build