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

centos6installationlinuxPHP

This may seem trivial to some, but I have been developing on Windows all my life and only moved to Linux this week – all is new to me.

I've been following The following guide on how to install php extensions on Linux. It worked perfectly for the mbstring extension, however, when I tried to do the exact same for bz2 and curl, I would get the error:
configure: error: Cannot find php-config. Please use --with-php-config=PATH

Has anyone encountered this error before and could shed some light in terms a rookie could understand? Both extensions came with the PHP 5.5 source. My commands used and their outputs are as follows:

Find php-config:

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

Confirm php-config exists:

[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

config and error

[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

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

Best Answer

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.