php编译安装扩展库
•编译安装PHP时启用的扩展,属于静态扩展,如需改动,只能重新编译安装PHP;
•安装完PHP后,通过phpize安装的动态扩展,是可以通过重新编译安装进行改动的,不需要重新编译安装PHP。
一、源码编译安装(一般是安装PHP自带的扩展,以安装pcntl扩展为例)
1、利用php -v命令查看当前的PHP CLI的版本
~# php -v
PHP 5.3.29-1~dotdeb.0 with Suhosin-Patch (cli) (built: Aug 14 2014 19:55:20)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies
2、根据版本下载PHP源代码
PHP历史版本下载页面:http://php.net/releases/
3、解压源码压缩包
例如下载的压缩包名称是php-5.3.29.tar.gz
~# tar -zxvf php-5.3.29.tar.gz
php-5.3.29/
php-5.3.29/README.WIN32-BUILD-SYSTEM
php-5.3.29/netware/
…
4、进入源码中的ext/pcntl目录
~# cd php-5.3.29/ext/pcntl/
5、运行 phpize 命令
~# phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
6、运行 configure命令
~# ./configure
checking for grep that handles long lines and -e… /bin/grep
checking for egrep… /bin/grep -E
…
7、运行 make 命令
~# make
/bin/bash /tmp/php-5.3.29/ext/pcntl/libtool –mode=compile cc …
-I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend…
…
8、运 行make install 命令
~# make install
Installing shared extensions: /usr/lib/php5/20090626/
9、配置ini文件
通过运行 php –ini查找php.ini文件位置,然后在文件中添加extension=pcntl.so
说明: 此方法一般用来安装PHP自带的扩展,例如posix扩展和pcntl扩展。除了用phpize编译某个扩展,也可以重新编译整个PHP,在编译时用参数添加扩展,例如在源码根目录运行
~# ./configure –enable-pcntl –enable-posix …
~# make && make install
二、phpize安装
如果要安装的扩展在php源码ext目录中没有,那么这个扩展需要到http://pecl.php.net 搜索下载
以安装libevent扩展为例(假设系统安装了libevent-dev库)
1、下载libevent扩展文件压缩包(在当前系统哪个目录下载随意)
~# wget http://pecl.php.net/get/libevent-0.1.0.tgz
–2015-05-26 21:43:40– http://pecl.php.net/get/libevent-0.1.0.tgz
Resolving pecl.php.net… 104.236.228.160
Connecting to pecl.php.net|104.236.228.160|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 9806 (9.6K) [application/octet-stream]
Saving to: “libevent-0.1.0.tgz”
100%[=======================================================>] 9,806 41.4K/s in 0.2s
2、解压扩展文件压缩包
~# tar -zxvf libevent-0.1.0.tgz
package.xml
libevent-0.1.0/config.m4
libevent-0.1.0/CREDITS
libevent-0.1.0/libevent.c
….
3、进入到源码目录
~# cd libevent-0.1.0/
4、运行phpize命令
~# phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
5、运行configure命令
~# ./configure
checking for grep that handles long lines and -e… /bin/grep
checking for egrep… /bin/grep -E
checking for a sed that does not truncate output… /bin/sed
checking for cc… cc
checking whether the C compiler works… yes
…
6、运行make命令
~# /bin/bash /data/test/libevent-0.1.0/libtool –mode=compile cc -I. -I/data/test/libevent-0.1.0 -DPHP_ATOM_INC -I/data/test/libevent-0.1.0/include
…
7、运行make install命令
~# make install
Installing shared extensions: /usr/lib/php5/20090626/
8、配置ini文件
通过运行 php –ini查找php.ini文件位置,然后在文件中添加extension=libevent.so
转载请注明:崔之龙–运维小崔的个人博客 » php编译安装扩展库
还没有人抢沙发呢~