Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PECL extensions installation fails after update MacOS to Mojave (10.14)

I use my Mac to develop three projects: a Android app, a iPhone app, and a Symfony project.

My Symfony project uses Redis and APCu extensions. This was installed (6 months ago) via PECL using:

sudo pecl install redis

and

sudo pecl install apcu

Yesterday, after update my mac to Mojave, and try to start my PHP's built-in Web Server as usual, I get the following error:

Attempted to load class "Redis" from the global namespace. Did you forget a "use" statement?

I also noticed that php.ini was removed during the installation, so I used the php.ini-previous to generate the php.ini again.

Also re-installed the Command Line Tools (was removed during installation):

xcode-select --install

And finally, I tried to install the redis extenison via PECL, again:

sudo pecl install redis

This time PECL throws an error:

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/sh /private/tmp/pear/temp/pear-build-root1vQ0zO/redis-4.1.1/libtool --mode=compile cc  -I. -I/private/tmp/pear/temp/redis -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-root1vQ0zO/redis-4.1.1/include -I/private/tmp/pear/temp/pear-build-root1vQ0zO/redis-4.1.1/main -I/private/tmp/pear/temp/redis -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /private/tmp/pear/temp/redis/redis.c -o redis.lo
mkdir .libs
cc -I. -I/private/tmp/pear/temp/redis -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-root1vQ0zO/redis-4.1.1/include -I/private/tmp/pear/temp/pear-build-root1vQ0zO/redis-4.1.1/main -I/private/tmp/pear/temp/redis -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/temp/redis/redis.c  -fno-common -DPIC -o .libs/redis.o
In file included from /private/tmp/pear/temp/redis/redis.c:27:
/private/tmp/pear/temp/redis/common.h:1:10: fatal error: 'php.h' file not found
#include "php.h"
         ^~~~~~~
1 error generated.
make: *** [redis.lo] Error 1
ERROR: `make' failed

How can solve this issue?

like image 347
Isaac Bosca Avatar asked Sep 26 '18 08:09

Isaac Bosca


2 Answers

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

$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
like image 85
donatJ Avatar answered Sep 19 '22 18:09

donatJ


You'll want to do

$ locate php.h

results should be something like:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/main/php.h /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/php/main/php.h

Next, you'll want to disable SIP so you can create a folder in /usr/include and symlink the php dev dependencies to this folder, You have to boot into recovery to do this; restart you machine then hold cmd + R while it restarts, select terminal from the utilities menu.

run # csrutil disable && shutdown -r now

this will disable SIP and restart your machine.

Once your booted in, you'll want to create that folder we talked about like so sudo mkdir /usr/include

next we create a symlink to where the php dev files are located

$ ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/php /usr/include

You'll still have to enable SIP back, so boot back into recovery mode this time around you'll run

# csrutil enable && shutdown -r now, and thats it.

like image 29
Eyo Okon Eyo Avatar answered Sep 20 '22 18:09

Eyo Okon Eyo