CentOS6 PHP 扩展安装:找不到 php-config。请使用 --with-php-config=PATH

CentOS6 PHP 扩展安装:找不到 php-config。请使用 --with-php-config=PATH

对某些人来说这可能看起来微不足道,但我一生都在 Windows 上进行开发,直到本周才转到 Linux——这一切对我来说都是新的。

我一直在关注以下指南关于如何在 Linux 上安装 php 扩展。它对于 mbstring 扩展来说运行良好,但是,当我尝试对 bz2 和 curl 执行完全相同的操作时,我会收到错误: configure: error: Cannot find php-config. Please use --with-php-config=PATH

有没有人遇到过这个错误,可以用新手能理解的术语来解释一下?这两个扩展都附带了 PHP 5.5 源代码。我使用的命令及其输出如下:

查找 php-config:

[Art@art ~]$ sudo find -name php-config
./php/scripts/php-config

确认 php-config 存在:

[Art@art bz2]$ cd ~/php/scripts
[Art@art scripts]$ ls -ltr
total 48
-rw-r--r--. 1 Art  Art  4690 May 28 09:06 phpize.m4
-rw-r--r--. 1 Art  Art  4499 May 28 09:06 phpize.in
-rw-r--r--. 1 Art  Art  2070 May 28 09:06 php-config.in
-rw-r--r--. 1 Art  Art  1744 May 28 09:06 Makefile.frag
drwxr-xr-x. 3 Art  Art  4096 May 28 09:06 dev
drwxr-xr-x. 2 Art  Art  4096 May 28 09:06 apache
-rw-r--r--. 1 root root 4522 Jun 25 09:16 phpize
-rw-r--r--. 1 root root 2260 Jun 25 09:16 php-config
drwxr-xr-x. 2 Art  Art  4096 Jun 25 09:16 man1

phpize bz2

[Art@art scripts]$ cd ~/php/ext/bz2
[Art@art bz2]$ phpize
Configuring for:
PHP Api Version:         20121113
Zend Module Api No:      20121212
Zend Extension Api No:   220121212

配置和错误

[Art@art bz2]$ sudo ./configure --with-php-config=~/php/scripts/php-config
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 for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
configure: error: Cannot find php-config. Please use --with-php-config=PATH

运行 php-config:

Usage: /usr/local/bin/php-config [OPTION]
Options:
  --prefix            [/usr/local]
  --includes          [-I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local
/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib]
  --ldflags           []
  --libs              [-lcrypt   -lresolv -lcrypt -lrt -lrt -lm -ldl -lnsl  -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm
 -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt ]
  --extension-dir     [/usr/local/lib/php/extensions/no-debug-zts-20121212]
  --include-dir       [/usr/local/include/php]
  --man-dir           [/usr/local/php/man]
  --php-binary        [/usr/local/bin/php]
  --php-sapis         [ apache2handler cli cgi]
  --configure-options [--with-apxs2=/usr/local/apache2/bin/apxs --with-mysql]
  --version           [5.5.13]
  --vernum            [50513]

答案1

您需要安装开发包:

# yum install php-devel

哪个软件包包括/usr/bin/php-config。当您计划另辟蹊径并编译自己的内容时,这通常适用于 RH/CentOS 组件;软件包foo-devel包含必要的内容,可让您针对 进行编译foo。进行分离是为了让那些不想手动构建内容的管理员不必安装所有钩子。

编辑:我并不是说你不应该从源代码构建扩展;只是说如果你想这样做,你需要php-devel。但你在评论中所说的表明你正在尝试重建整个 PHP - 在这种情况下,你不能从扩展开始,你需要构建整个 PHP,从 PHP 开始。

如果您可以明确您可以使用的 PHP 最低版本,那么获取它可能会比构建它更好的途径。

答案2

我猜你没有正确匹配 phpize 和 php-config。确保你使用的是同一个安装中的两个。因此,如果你使用某些前缀配置 php $A,请使用:

$A/bin/phpize
./configure --with-php-config=$A/bin/php-config

顺便说一句,您不应该使用 构建捆绑扩展phpize。它大部分情况下都能工作,但不能保证(我尝试了 curl 和 bz2 扩展,这两个似乎确实有效)。您应该使用--enable-<extension>=shared或重建 php --with-<extension>=shared(传递--help给 configure 以检查哪一个)。

此外,出于多种原因(易于删除、可以处理升级、构建包后无需编译等),使用包通常是一个好主意。它还可以避免因安装多个版本而产生的错误。使用 相对容易fpm

sudo yum install ruby-devel rubygems; sudo gem install fpm
curl -L http://ca1.php.net/get/php-5.5.13.tar.bz2/from/this/mirror | tar xjf -
cd php-5.5.13/
./configure --prefix=/usr --disable-all --enable-mbstring=shared # edit config line to your taste
make -j8
make install INSTALL_ROOT=root
# you can optionally strip the binaries at this point
# a simple would be find root | xargs strip
cd root
# add dependencies with -d foo if necessary, for instance -d libcurl
fpm -s dir -t rpm -n php -v 5.5.13 .
sudo yum localinstall php-5.5.13-1.x86_64.rpm

相关内容