26

What i should do when i run PHPIZE and get the error below ? I already installed xcode command line tools.

grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:        
Zend Module Api No:     
Zend Extension Api No:
delphirules
  • 6,443
  • 17
  • 59
  • 108

4 Answers4

72

Potential better solution - force reinstall the header files. Fixed a ton of problems for me system wide.

Running the following command will reinstall the developer tools header files and should fix the issue.

$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
donatJ
  • 3,105
  • 3
  • 32
  • 51
  • 3
    Not potential. Absolutely the better solution. – tuxedobob Nov 30 '18 at 19:54
  • 4
    Thanks. This works and fixes everything for the OS installed PHP. I came across this issue while trying to setup xdebug. – Jabran Rafique Jan 09 '19 at 14:57
  • had need to run `xcode-select --install` first. after a re-install of my OS xcode was gone. i guess. – André Kelling Mar 13 '19 at 10:26
  • 1
    It appears the new version of Xcode may have removed this pkg. I have not found a solution yet. – donatJ Jul 08 '19 at 16:57
  • Before I could run the above command I also had to re-install Xcode developer tools from here: https://developer.apple.com/download/more/ and specifically had to select "Command Line Tools (macOS 10.14) for Xcode 10.2" – kk64738 Oct 01 '19 at 17:28
  • How to apply this solution for MacOs Catalina ? – delphirules Nov 04 '19 at 12:01
  • @delphirules have you found a solution for MacOS Catalina? – Abana Clara Nov 05 '19 at 08:33
  • @AbanaClara Not yet, i opened a new quesiton : https://stackoverflow.com/questions/58693002/unable-to-use-phpize-after-update-to-macos-catalina – delphirules Nov 05 '19 at 11:51
  • 3
    This does not work for me. I get the following error: ```"The install failed (The Installer encountered an error that caused the installation to fail. Contact the software manufacturer for assistance.)"``` – ludovico Nov 27 '19 at 17:37
4

For some reason, I found Xcode command line tools was not installed completely on my Mac, Finally I solved this problem as follow:

 1. xcode-select --install
 2. cd /Library/Developer/CommandLineTools/Packages/ 
 3. open macOS_SDK_headers_for_macOS_10.14.pkg

Note: After doing step2, if there is no .pkg file in the dir. maybe this solution will not help you.

janko
  • 41
  • 4
2

find the phpize and edit it,

~$ whereis phpize
phpize: /usr/local/bin/phpize
~$ vim  /usr/local/bin/phpize

in my phpize script it is like that

prefix='/usr/local/php7'   ## where you should edit
datarootdir='/usr/local/php7/php'
exec_prefix="`eval echo ${prefix}`"
phpdir="`eval echo ${exec_prefix}/lib/php`/build"
includedir="`eval echo ${prefix}/include`/php"
...

phpize_get_api_numbers()
{
  # extracting API NOs:
  PHP_API_VERSION=`grep '#define PHP_API_VERSION' $includedir/main/php.h|$SED 's/#define PHP_API_VERSION//'`
  ZEND_MODULE_API_NO=`grep '#define ZEND_MODULE_API_NO' $includedir/Zend/zend_modules.h|$SED 's/#define ZEND_MODULE_API_NO//'`
  ZEND_EXTENSION_API_NO=`grep '#define ZEND_EXTENSION_API_NO' $includedir/Zend/zend_extensions.h|$SED 's/#define ZEND_EXTENSION_API_NO//'`
}

if you comfirm that you have the header file but the phpize script configure is wrong ,you can edit the row

prefix='/usr/local/php7'

and php.h is in

$ pwd
/usr/local/php7/include/php/main
$ ls  php.*
php.h

if not ,you can compile php by yourself

Mattia Dinosaur
  • 891
  • 10
  • 29
  • My php folder is /usr/local/php5-7.1.10-20171002-090111 . i edited prefix='/usr/local/php5-7.1.10-20171002-090111' and datarootdir='/usr/local/php5-7.1.10-20171002-090111/php', but i still get the same error when calling PHPIZE... any hints ? – delphirules Oct 01 '18 at 16:19
  • Actually this file : "/usr/include/php/main/php.h" is on "/usr/local/php5-7.1.10-20171002-090111/include/php/main" – delphirules Oct 01 '18 at 16:21
  • do you have more than one phpize script? – Mattia Dinosaur Oct 01 '18 at 22:54
  • 1
    No. I could solve the problem after doing what you suggested., thanks ! – delphirules Oct 02 '18 at 13:19
  • 2
    Now i upgraded to Catalina, i'm having the same issue, but i can't edit phpize anymore even as sudo, i get this error : "Failed to save 'phpize': Command failed: "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" --file-write "/var/folders/dc/3d93lth116q91kx94ms37rd40000gn/T/code-elevated-dynago" "/usr/bin/phpize" Error using --file-write: EPERM: operation not permitted, open '/usr/bin/phpize'" – delphirules Nov 04 '19 at 11:44
  • `phpize` is a readonly file. even cannot be edited by `sudo` – Raptor Sep 09 '20 at 03:15
-2

I had the same issue as described above, only I was trying to install xdebug on macOS Mojave.

I resolved the issue by executing:

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
Jens Buysse
  • 119
  • 10