使用
phpize
为PHP动态添加扩展
时,报Cannot find autoconf
错误
$ /app/php/bin/phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
$ yum -y install m4 autoconf #手动编译m4和autoconf亦可(不推荐) --> 解决方案
$ /app/php/bin/phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
为PHP添加php-curl扩展
$ ./configure \
--prefix=/app/php \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-sockets \
--enable-fpm \
--with-config-file-path=/etc/ \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2 \
--with-gd \
--with-curl
...省略中间的Check过程...
checking for cURL 7.10.5 or greater... configure: error: cURL version 7.10.5 or later is required to compile php with cURL support #环境检查程序检测到需要cURL版本7.10.5或更高版本才能使用cURL支持编译php,意即当前PHP源码包中的cURL版本较旧,不支持'--with-curl'编译选项
$ yum -y install curl-devel
$ wget -O /usr/src/curl-7.64.0.tar.gz https://curl.haxx.se/download/curl-7.64.0.tar.gz
$ cd /usr/src
$ tar xf curl-7.64.0.tar.gz
$ cd curl-7.64.0
$ /app/php/bin/phpize
Cannot find config.m4. #提示未发现config.m4文件
Make sure that you run '/app/php/bin/phpize' in the top level source directory of the module
$ cp /usr/src/php-7.2.5/ext/curl/config.m4 . #拷贝PHP源码包中的config.m4文件到当前目录下
$ /app/php/bin/phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
$ ./configure --with-php-config=/app/php/bin/php-config #调用configure生成Makefile文件,指定phpize要建立基于哪个php版本的扩展
$ make -j4 #编绎
$ make install #复制安装
$ find /usr/local/ -name 'curl.so' #查找生成的curl.so文件
/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/curl.so
$ cat /etc/php.ini | grep curl.so #将curl.so文件路径添加到php.ini的extension(扩展)部分
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/curl.so
$ service php-fpm restart #重启`PHP-FPM`程序以重载php.ini文件
$ php-fpm -m | grep curl #检查php-curl扩展是否添加成功
curl
PHP连接远程DB服务器
MySQL
为例 $ yum -y install php-mysql
为PHP添加GD库扩展
【附注】
command not found
的错误,此时需要手动指定phpize路径
,一般在$PHP_INSTALL_PATH/bin/
下;phpize
用于扩展php模块
,无论是通过手动编译
还是通过yum
等软件包管理器
都会生成phpize文件。该文件中记录了PHP
的安装信息和相关变量,因此由于不同组织或个人编译PHP时的需求不尽相同,不能从其他地方直接拷贝phpize文件使用,而应在编译好PHP后对该文件做好备份
或找到自己对应PHP版本
的phpize文件;curl
和安装php-curl
是有区别的,但源码包是一样的;