php扩展安装
php扩展,我的理解就是,不支持某种功能(开始编译php时)的一种补救措施!
我们一般都喜欢编译php的源码,它的扩展都在源码解压后的ext目录下
/home/software/php-5.2.10/ext(例如:我的php解压目录)
/usr/local/php5/bin/phpsize (php的安装目录)
这里有很多的扩展,我们常用的有pdo、mysqli、pdo_mysql
pdo的扩展安装:
cd pdo
/usr/local/php5/bin/phpize
/usr/local/php5/bin/phpize
./configure --help
./configure --with-php-config=/usr/local/php5/bin/php-config
make
make test #就算这里提示出错,不要理它!
make install
pdo_mysql扩展安装:
cd pdo_mysql/
/usr/local/php5/bin/phpize
执行这一步需要autoconf
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF
environment variable is set correctly and then rerun this script.
[root@tuiguangvm pdo]# yum -y install autoconf*
即可解决!
./configure --with-php-config=/usr/local/php5/bin/php-config --with-pdo-mysql=/usr/local/mysql5/
make
make install
mysqli扩展安装:
cd mysqli/
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php5/bin/php-config --with-mysqli=/usr/local/mysql5/bin/mysql_config
make
make test 有报错:
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php5/bin/php-config --with-mysqli=/usr/local/mysql5/bin/mysql_config
make
make test 有报错:
Build complete.
Don't forget to run 'make test'.
+-----------------------------------------------------------+
| ! ERROR ! |
| The test-suite requires that proc_open() is available. |
| Please check if you disabled it in php.ini. |
+---------------------------------------------
Don't forget to run 'make test'.
+-----------------------------------------------------------+
| ! ERROR ! |
| The test-suite requires that proc_open() is available. |
| Please check if you disabled it in php.ini. |
+---------------------------------------------
解决方法:
vi /usr/local/conference/php.ini
|
找到disable_functions = shell_exec, system, passthru, exec, popen, proc_open()
改为disable_functions = shell_exec, system, passthru, exec, popen
保存退出。
接着
1
|
make test
|
通过测试就
make install
到此已经安装完成!
可以去查看是否已经生成*.so文件。见附件
也可以用phpinfo();函数来测试!
测试见附件:
freebsd下安装php扩展遇到的问题及解决方法:
运行/usr/local/php5/bin/phpize提示找不到auto_conf包!
出现的故障和解决方法:
1:checking for the location of libz... no
checking for mysql_config... not found
configure: error: Cannot find MySQL header files under
在安装pdo_mysql扩展时,提示的错误
解决方法:
在configure时添加另外一个参数即可!
%./configure --with-php-config=/usr/local/php5/bin/php-config --with-pdo-mysql=/usr/local/mysql5 ##mysql的安装目录
checking for mysql_config... not found
configure: error: Cannot find MySQL header files under
在安装pdo_mysql扩展时,提示的错误
解决方法:
在configure时添加另外一个参数即可!
%./configure --with-php-config=/usr/local/php5/bin/php-config --with-pdo-mysql=/usr/local/mysql5 ##mysql的安装目录
安装步骤:
cd php-5.2.10
cd ext/
cd pdo_mysql
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php5/bin/php-config --with-pdo-mysql=/usr/local/mysql5
make
make install
cd php-5.2.10
cd ext/
cd pdo_mysql
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php5/bin/php-config --with-pdo-mysql=/usr/local/mysql5
make
make install
2:pdo扩展的安装:
cd php-5.2.10
cd ext/
cd pdo
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php5/bin/php-config
make
make install
3:php安装mysqli
cd php-5.2.10
cd ext/
cd mysqli/
cd php-5.2.10
cd ext/
cd mysqli/
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php5/bin/php-config --with-mysqli=/usr/local/mysql5/bin/mysql_config
make
make install
4:安装mcrypt扩展
checking for mcrypt support... yes, shared
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决方法:我安装libmcrypt-2.5.7
再次编译时出错如下:
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for mcrypt support... yes, shared
checking for libmcrypt version... >= 2.5.6
checking for mcrypt_module_open in -lmcrypt... no
checking for mcrypt_module_open in -lmcrypt... no
configure: error: Sorry, I was not able to diagnose which libmcrypt version you have installed.
怀疑是libmcrypt版本不兼容所致!
make
make install
4:安装mcrypt扩展
checking for mcrypt support... yes, shared
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决方法:我安装libmcrypt-2.5.7
再次编译时出错如下:
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for mcrypt support... yes, shared
checking for libmcrypt version... >= 2.5.6
checking for mcrypt_module_open in -lmcrypt... no
checking for mcrypt_module_open in -lmcrypt... no
configure: error: Sorry, I was not able to diagnose which libmcrypt version you have installed.
怀疑是libmcrypt版本不兼容所致!
293 16:45 tar jxvf libmcrypt-2.5.8.tar.bz2
cd libmcrypt-2.5.8
./configure --prefix=/usr/local/libcrypt
make
make install
中间我怀疑是php被弄乱(因为在libmcrypt不同的版本下,phpize运行了几次),将php删除后重新解压
cd php-5.2.10
cd libmcrypt-2.5.8
./configure --prefix=/usr/local/libcrypt
make
make install
中间我怀疑是php被弄乱(因为在libmcrypt不同的版本下,phpize运行了几次),将php删除后重新解压
cd php-5.2.10
cd ext/
cd mcrypt/
cd mcrypt/
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php5/bin/php-config --with-mcrypt=/usr/local/libcrypt
make
make install
./configure --with-php-config=/usr/local/php5/bin/php-config --with-mcrypt=/usr/local/libcrypt
make
make install
5:%./install-tty
5.1:
/libexec/ld-elf.so.1: Shared object "libm.so.4" not found, required by "php"
解决方法:
%ln -s /usr/lib/libm.so /usr/lib/libm.so.4
5.2:
%./install-tty
/libexec/ld-elf.so.1: Shared object "libutil.so.5" not found, required by "php"
解决方法:
%ln -s /usr/lib/libutil.so /usr/lib/libutil.so.5
5.3:
%./install-tty
/libexec/ld-elf.so.1: Shared object "libcrypt.so.3" not found, required by "php"
解决方法:
%ln -s /usr/lib/libcrypt.so /usr/lib/libcrypt.so.3
%./install-tty
/libexec/ld-elf.so.1: Shared object "libcrypt.so.3" not found, required by "php"
解决方法:
%ln -s /usr/lib/libcrypt.so /usr/lib/libcrypt.so.3
5.4:
%./install-tty
/libexec/ld-elf.so.1: Shared object "libc.so.6" not found, required by "php"
解决方法:
% ln -s /usr/lib/libc.so /usr/lib/libc.so.6
6:查看freebsd下安装的package
%pkg_info | grep perl
perl-5.8.8_1 Practical Extraction and Report Language
%pkg_info | grep auto
autoconf-2.62 Automatically configure source code on many Un*x platforms
autoconf-wrapper-20071109 Wrapper script for GNU autoconf
%cd
%./install-tty
/libexec/ld-elf.so.1: Shared object "libc.so.6" not found, required by "php"
解决方法:
% ln -s /usr/lib/libc.so /usr/lib/libc.so.6
6:查看freebsd下安装的package
%pkg_info | grep perl
perl-5.8.8_1 Practical Extraction and Report Language
%pkg_info | grep auto
autoconf-2.62 Automatically configure source code on many Un*x platforms
autoconf-wrapper-20071109 Wrapper script for GNU autoconf
%cd
7:安装php扩展时,出现问题,提示can not find autoconf
见附件:
解决方法:安装autoconf的rpm包即可
8:安装mhash扩展时,提示出错:
configure:error:please reinstall libmhash -I can not find libmhash.h
见附件:
解决方法:先安装mhash-0.9.9.9.tar.bz2 ,然后configue mhash扩展,问题即可解决!
最后在php.ini中加入:
extension_dir = "/usr/local/php5/lib/php/extensions"
extension="no-debug-zts-20060613/mhash.so"
测试方法:用phpinfo();来测试,如果能在显示的内容中看到mhash的字样,则表示已经支持mhash
9:memcache安装:
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5
/usr/local/php5/bin/phpize
./configure
--with-php-config=/usr/local/php5/bin/php-config
##configure时需要指定--with-php-config,否则会有如下错误:
configure: error: Cannot find php-config. Please use --with-php-config=PATH
##configure时需要指定--with-php-config,否则会有如下错误:
configure: error: Cannot find php-config. Please use --with-php-config=PATH
make
make test
make install
然后在php.ini中加入:
extension_dir = "/usr/local/php5/lib/php/extensions"
extension="no-debug-zts-20060613/memcache.so"
测试:用phpinfo();来测试,如果能在显示的内容中看到memcache的字样,则表示已经支持memcache
测试见附件:
10:eAccelerator 扩展安装:
export PHP_PREFIX="/usr/local/php"
$PHP_PREFIX/bin/phpize
./configure \
--enable-eaccelerator=shared \
--with-php-config=$PHP_PREFIX/bin/php-config
make
make test
make test 即可安装!
特别注意到一点是:eAccelerator 和 Zend Optimizer冲突,必须将eAccelerator的相关配置放到Zend Optimizer前面,如果放在Zend Optimizer后面,apache会启动失败,后台日志中有如下提示:
PHP Fatal error: [Zend Optimizer] Zend Optimizer 3.3.0 is incompatible with eAccelerator 0.9.5.3 in Unknown on line 0
解决方法:将eAccelerator的相关配置放到Zend Optimizer前面即可!
在php.ini中加入:
[eaccelerator]
zend_extension_ts="/usr/local/php5/lib/php/extensions/no-debug-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="128"
eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="300"
eaccelerator.shm_prune_period="120"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
用/usr/local/php/bin/php -v 和phpinfo()函数测试都可以! 看到eaccelerator的相关字样即表示已经安装成功!
见附件:
11:imagick扩展安装
imagick是一个PHP的扩展,用ImageMagick提供的API来进行图片的创建与修改,不过这些操作已经包装到扩展imagick中去了,最终调用的是ImageMagick提供的API,mageMagick是一套软件系列,主要用于图片的创建、编辑以及转换等,ImageMagick与GD的性能要高很多,如果是在处理大量的图片时更加能体现ImageMagick的性能。由于安装imagick扩展时需要依赖ImageMagick的函数库,因此必须要先安装ImageMagick
开始我下载imagick-2[1].3.0.tgz和ImageMagick-6.5.1-10.tar.gz 倒是可以安装上,但phpinfo中无法看到imagick扩展,/usr/local/php/bin/php -v时有错误提示:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/php5/lib/php/extensions/no-debug-zts-20060613/imagick.so'
- libgomp.so.1: shared object cannot be dlopen()ed in Unknown on line 0
安装:
tar jxvf ImageMagick-6.7.9-8.tar.bz2
make
make install
tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
安装:
tar jxvf ImageMagick-6.7.9-8.tar.bz2
cd ImageMagick-6.7.9-8
./configure
make
make install
tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
出错见附件:
网上搜了下有人说把gcc升级到4.1.2问题即可解决,我查了下本人的gcc版本为:
gcc 版本 4.1.1 20070105 (Red Hat 4.1.1-52)
但考虑到升级gcc还有他需要的依赖包很可能也需要升级,而且rpm包的依赖性很强,就没有进行升级!
而是选择低版本的软件进行测试,试着下载ImageMagick-5.* 和 ImageMagick-4.* 安装的时候都失败,尝试下载ImageMagick-6.2.5-5.tar.gz 和 imagick-2.2.2.tgz,成功安装,并在php.ini中加入:
extension_dir = "/usr/local/php5/lib/php/extensions"
extension="no-debug-zts-20060613/imagick.so"
然后测试见附件:
12:SCWS安装
SCWS-1.2.1 安装说明
以 Linux(FreeBSD) 操作系统为例
1. 取得 scws-1.2.1 的代码
wget http://www.xunsearch.com/scws/down/scws-1.2.1.tar.bz2
2. 解开压缩包
[hightman@d1 ~]$ tar xvjf scws-1.2.1.tar.bz2
3. 进入目录执行配置脚本和编译
[hightman@d1 ~]$ cd scws-1.2.1[hightman@d1 ~/scws-1.2.1]$ ./configure --prefix=/usr/local/scws ; make ; make install
注:这里和通用的 GNU 软件安装方式一样,具体选项参数执行 ./configure --help 查看。
常用选项为:--prefix=
4. 顺利的话已经编译并安装成功到 /usr/local/scws 中了,执行下面命令看看文件是否存在
[hightman@d1 ~/scws-1.2.1]$ ls -al /usr/local/scws/lib/libscws.la
5. 试试执行 scws-cli 文件
[hightman@d1 ~/scws-1.2.1]$ /usr/local/scws/bin/scws -h
scws (scws-cli/1.2.1)
Simple Chinese Word Segmentation - Command line usage.
Copyright (C)2007 by hightman.
...
6 用 wget 下载并解压词典,或从主页下载然后自行解压再将 *.xdb 放入 /usr/local/scws/etc 目录中
[hightman@d1 ~/scws-1.2.1]$ cd /usr/local/scws/etc
[hightman@d1 /usr/local/scws/etc]$ wget http://www.xunsearch.com/scws/down/scws-dict-chs-gbk.tar.bz2
[hightman@d1 /usr/local/scws/etc]$ wget http://www.xunsearch.com/scws/down/scws-dict-chs-utf8.tar.bz2
[hightman@d1 /usr/local/scws/etc]$ tar xvjf scws-dict-chs-gbk.tar.bz2
[hightman@d1 /usr/local/scws/etc]$ tar xvjf scws-dict-chs-utf8.tar.bz2
7. 写个小程序测试一下
[hightman@d1 ~]$ cat > test.c
#include
#include
main()
{
scws_t s;
s = scws_new();
scws_free(s);
printf("test ok!\n");
}
8. 编译测试程序
gcc -o test -I/usr/local/scws/include -L/usr/local/scws/lib test.c -lscws -Wl,--rpath -Wl,/usr/local/scws/lib
./test
9. 这样就好顺利安装完毕可以使用 libscws 这套 C-API 了
10. 如果您需要在 php 中调用分词,建议继续阅读本文安装 php 扩展,否则可跳过不看。
假设您已经将 scws 按上述步骤安装到 /usr/local/scws 中。
安装此扩展要求您的 php 和系统环境安装了相应的 autoconf automake 工具及 phpize 。
1) 进入源码目录的 phpext/ 目录 ( cd ~/scws-1.2.1 )
2) 执行 phpize (在PHP安装目录的bin/目录下)
3) 执行 ./configure --with-scws=/usr/local/scws
若 php 安装在特殊目录 $php_prefix, 则请在 configure 后加上 --with-php-config=$php_prefix/bin/php-config
4) 执行 make 然后用 root 身份执行 make install
5) 在 php.ini 中加入以下几行
[scws]
;
; 注意请检查 php.ini 中的 extension_dir 的设定值是否正确, 否则请将 extension_dir 设为空,
; 再把 extension = scws.so 指定绝对路径。
;
extension = scws.so
scws.default.charset = gbk
scws.default.fpath = /usr/local/scws/etc
6) 命令行下执行 php -m 就能看到 scws 了或者在 phpinfo() 中看看关于 scws 的部分,记得要重启 web 服务器
才能使新的 php.ini 生效。
7) 这样就算安装完成了,余下的工作只是PHP代码编写问题了。
关于 PHP 扩展的使用说明请参看代码中 phpext/README.md 文件或其它文档章节。
这个摘抄之官方文档! 我在使用的过程中遇到一个问题:
test.c:1:18: error: scws.h: No such file or directory
gcc -o test -I /usr/local/scws/include/scws -L/usr/local/scws/lib test.c -lscws -Wl,--rpath -Wl,/usr/local/scws/lib ##红色的字体为修改的部分
13:APC扩展安装
tar zxvf APC-3.1.9.tgz
cd APC-3.1.9
/usr/local/php/bin/phpize
./configure --enable-apc --enable-apc-mmapa --with-php-config=/usr/local/php/bin/php-config
make
make install
14:xhprof 扩展安装
#tar zxvf xhprof-0.9.2.tgz
#cd xhprof-0.9.2
#cd xhprof-0.9.2/extension/
#/usr/local/php/bin/phpize
#./configure --with-php-config=/usr/local/php/bin/php-config
#make
#make install
test.c:1:18: error: scws.h: No such file or directory
gcc -o test -I /usr/local/scws/include/scws -L/usr/local/scws/lib test.c -lscws -Wl,--rpath -Wl,/usr/local/scws/lib ##红色的字体为修改的部分
13:APC扩展安装
tar zxvf APC-3.1.9.tgz
cd APC-3.1.9
/usr/local/php/bin/phpize
./configure --enable-apc --enable-apc-mmapa --with-php-config=/usr/local/php/bin/php-config
make
make install
#tar zxvf xhprof-0.9.2.tgz
#cd xhprof-0.9.2
#cd xhprof-0.9.2/extension/
#/usr/local/php/bin/phpize
#./configure --with-php-config=/usr/local/php/bin/php-config
#make
#make install
原文出自 http://blog.chinaunix.net/uid-20776139-id-1846958.html