centos下编译php扩展

新装了centos 6.2,用yum安装的php,发现少了mbstring、mcrypt扩展,可是在centos的repos里不再包括mcrypt的源文件,于是

1、下载php-5.3.11.tar.gz,找到ext/mcrypt,用phpize来进行扩展,发现phpize不能用;

2、rpm -q --whatprovides /usr/bin/phpize找出需要安装php-devel,
yum安装php-devel,可以phpize;

3、phpize、./configure编译mcrypt.so,告诉缺少mcrypt.h
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz

tar -zxvf libmcrypt-2.5.7.tar.gz 
cd libmcrypt-2.5.7 
mkdir -p /usr/local/libmcrypt 
./configure prefix=/usr/local/libmcrypt/ 
make
make install

4、再./configure,警告You will need re2c 0.13.4 or later if you want to regenerate PHP parsers

wget http://pkgs.repoforge.org/re2c/re2c-0.13.5-1.el6.rf.x86_64.rpm
rpm -i re2c-0.13.5-1.el6.rf.x86_64.rpm

还是缺少mcrypt.h,从/usr/local/libmcrypt/include下把mcrypt.h复制过去仍然不行

5、把mcrypt.h复制到/usr/include,再./configure提示无法确定libmcrypt的版本

6、重新编译libmcrypt后可以正常./configure了,但make出错
mcrypt.c:283: error: ‘PHP_FE_END’ undeclared here (not in a function)

7、源代码有错误,进入php-5.3.11目录
 
sed -i 's|PHP_FE_END|{NULL,NULL,NULL}|' ./ext/**/*.c
 
sed -i 's|ZEND_MOD_END|{NULL,NULL,NULL}|' ./ext/**/*.c

再编译安装,一切正常了

8、测试phpmyadmin,提示“无法载入 mcrypt 扩展,<br />请检查 PHP 配置”

9、编辑/etc/php.ini,加入

extension=/usr/lib64/php/modules/mcrypt.so

问题解决。

你可能感兴趣的:(centos下编译php扩展)