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 configure: error: Cannot find php-config. Please use --with-php-config=PATH

有没有人遇到过这个错误,并能从菜鸟的angular度来理解? 两个扩展都带有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 

configuration和错误

 [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] 

你需要安装devel软件包:

 # yum install php-devel 

哪个软件包包含/usr/bin/php-config 。 对于RH / CentOS组件,这通常是正确的,当你计划去滑雪道和编译自己的东西; foo-devel软件包包含必要的东西,允许您对foo进行编译。 分离完成后,那些不想手动构build东西的pipe理员不必安装所有的钩子。

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

如果你能澄清一下你能够忍受的最低版本的PHP,那么获取它的路线可能比构build它更好。

我猜你是不匹配phpize和php-config。 确保你使用的是同一个安装。 所以如果你用一些前缀$Aconfigurationphp,使用:

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

顺便说一句,你不应该build立与phpize捆绑扩展。 它将主要工作,但不能保证(我试过curl和bz2扩展,这两个似乎工作)。 你应该用--enable-<extension>=shared或者--with-<extension>=shared (pass --helpconfiguration来检查哪一个)重buildphp。

而且,使用软件包通常是一个好主意(出于多种原因)(易于清除,处理升级的可能性,在软件包build立之后不需要编译等等)。 这也可以避免你安装多个版本时出现的错误。 这与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