PHP扩展载入方法--我在新增mcrypt扩展时遇到的问题

来源:互联网 发布:毒狗药三步倒淘宝 编辑:程序博客网 时间:2024/04/29 22:57

一、PHP扩展库动态编译方法

通常PHP扩展库是可以动态编译加载的。首先要下载和你的php版本一样的源码包,例如要加载socket扩展:

#cd /home/php-5.4.26/ext/sockets //这里是php的源码包#/usr/local/php/bin/phpize //phpize的路径#./configure  --with-php-config=/usr/local/php/bin/php-config  --enable-socket //注意php-config的位置可能和你安装的有所不同#make#make install

然后在php.ini文件启用该扩展,重启服务器进程即可。

二、mcrypt的扩展安装(此方法安装完无效)

mcrypt需要三个包:libmcrypt, mhash, mcrypt.

下载源码,按以上顺序编译安装这三个包。然后用上面PHP扩展库编译方法编译安装mcrypt:

#cd /home/php-5.4.26/ext/mcrypt#/usr/local/php/bin/phpize#./configure  --with-php-config=/usr/local/php/bin/php-config  --enable-mcrypt#make#make install

如上安装完成之后,在php.ini文件启用扩展,然后重启php-fpm进程。

使用

查看已安装的PHP扩展,发现已经加载了mcrypt,但是使用phpinfo()看不到该扩展。


三、重新编译PHP安装mcrypt

在方法二中动态编译加载无效之后,我选择了重新编译PHP。

首先使用

<pre name="code" class="cpp">#/usr/local/php/lib/php -i | grep config

查看现有PHP的编译命令,然后进入PHP源码包,重新编译安装PHP,增加扩展 --with-mcrypt :

#./configure'  '--prefix=/usr/local/php' '--with-xpm-dir=/usr/lib64' '--with-gd=/usr/local/gd' '--with-jpeg-dir=/usr/local/jpeg' '--with-png-dir=/usr/local/png' '--with-freetype-dir=/usr/local/freetype' '--with-mysql=/usr/local/mysql' '--enable-fastcgi' '--enable-fpm' '--with-mcrypt'
此时在查看PHP已加载的动态库,发现已经加载了mcrypt,但是有一个报错,提示mcrypt扩展已经加载,这是因为方法二里面我在php.ini里面启用了mcrypt的扩展,重新注释掉即可。

至此使用phpinfo()查看,已经可以显示mcrypt扩展如下:




遗留问题:

1、不知道为何动态加载mcrypt没有加载成功,其背后的原理是什么?

2、PHP加载扩展都有哪几种方法?


四.常见问题

1、编译安装intl扩展,执行

#./configure

出现如下错误:

configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.

解决方法:

安装libicu-devel,然后重新编译即可.

0 0