CentOS6 PHP extension install: Cannot find php-config. Please use --with-php-config=PATH

Solution 1:

You need the devel package installed:

# yum install php-devel

which package includes /usr/bin/php-config. This is generally true for RH/CentOS components when you're planning on going off-piste and compiling your own stuff; the foo-devel package contains the necessary stuff to allow you to compile against foo. The separation is done so that those admins who aren't going to want to hand-build stuff don't have to have all the hooks installed.

Edit: I'm not saying you shouldn't build extensions from source; just that if you want to, you'll need php-devel. But what you say in your comment suggests that you're trying to rebuild the whole of PHP - in which case, you can't start with the extensions, you'll need to build the whole of PHP, starting with PHP.

If you can clarify what the minimum version of PHP you can live with is, there may be better routes to getting it than building it.

Solution 2:

I'd guess you're mismatching phpize and php-config. Make sure you're using both from the same installation. So if you configure php with some prefix $A, use:

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

BTW, you shouldn't be building bundled extensions with phpize. It will mostly work, but it's not guaranteed to (I tried the curl and bz2 extensions and those two do seem to work). You should instead rebuild php with --enable-<extension>=shared or --with-<extension>=shared (pass --help to configure to check which one).

Also, it's generally a good idea to use packages, for several reasons (easy removals, possibility to handle upgrades, no compiling necessary after the package has been built, and so on). It would also avoid the kind of mistakes you get from having multiple versions installed. This relatively easy to do with 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