Unable to use PHPIZE after update to MacOS Mojave
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 /
How to load memcached on PHP in Mac OS X Catalina?
So I was able to find a solution after 2 working days. What you should do is move away from using built-in Apache/PHP from macOS and use the ones from Homebrew.
Here are the descriptive step-by-step procedure I did:
1) Unload the built-in Apache.
2) Install a new Apache from Homebrew via brew install httpd
and then run the service
3) Install PHP via brew install php
4) Configure httpd.conf from /usr/local/etc/httpd/
, including loading Homebrew PHP module, mod_rewrite, setting up DirectoryIndex, ServerName, default Listen port, etc.
4.1) If you are using virtual hosts, set this up on /usr/local/etc/httpd/extra/
5) Configure ~/.bash_profile to use the new PHP version (test via php -v
or which php
)
6) Install PEAR
7) Install memcached via PEAR
I have compiled a list of links that you can use:
Apache & PHP Installation
https://tecadmin.net/install-apache-macos-homebrew/
https://getgrav.org/blog/macos-catalina-apache-multiple-php-versions
https://gist.github.com/DragonBe/0faebe58deced34744953e3bf6afbec7
Follow brew info php
to configure Homebrew PHP to Homebrew Apache
Configure bash profile to use homebrew php by default
PHP --version shown incorrectly on osX
How to use the php that brew installed?
Install PEAR and configure
https://jasonmccreary.me/articles/install-pear-pecl-mac
Install memcached via PEAR
pecl install memcached
then follow instructions
Or
How to install memcached module for php@7.1 on MacOS High Sierra?
https://donatstudios.com/OS-X-Mavericks-Memcached-PHP-Extension-Installation
Can I install the memcached PHP extension with PECL?
Installation of Xdebug on MacOS Catalina 10.15
Update
For anyone that just want xdebug support on MacOS, most of the instructions in this answer are not necessary when using the built-in version of PHP. Before doing anything, you should check ifxdebug.so
already exists in /usr/lib/php/extensions/no-debug-non-zts-20180731/
, which should be there by default. If so, you can skip to the Enabled support in PHP portion of this answer.Using Homebrew is also an acceptable solution for you (and can also prevent other issues).
For anyone else looking to actually build binaries on MacOS and get the header error, the full answer is for you. It also answer OP question directly. Note building xdebug from source code and actually trying to use that version of xdebug.so
with the build-in PHP should end up in a "code signature" error. As described here and here, the only real solution would be to compile and use you own instance of PHP instead of the built-in one. In any situation, using Homebrew would be easier.
tl;dr
Apple decided to remove headers file in/usr/include
and the macOS_SDK_headers_for_macOS_10.14.pkg
package. To install Xdebug, you'll have to manually compile Xdebug with the correct reference in both phpize
and make
.For more details, I wrote a blog article about the issue and the solution
Original Answer:
Long story short, Apple decided to nuke/usr/include
in MacOS Catalina, which has been the default location for C header file for ever in UNIX systems. Trying to install through PEAR / PECL will return an error as the compiler will look for necessary headers file in /usr/include
. So the solution is to compile Xdebug manually, manually specifying the actual location of the header files, which are still provided by Xcode, just at a different location.First, make sure Xcode is installed, including the command line tools. The following command will display the location of the default SDK :
$ xcrun --show-sdk-path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
The header you'll want (php.h
) will then be in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/main
.Getting source
Let's compile 2.7.2, getting the source code from git. Alternatively, you can download the source from Xdebug site.git clone https://github.com/xdebug/xdebug.git
cd xdebug
git checkout tags/2.7.2
phpize
Next we need to make a copyphpize
so we can edit the include path :cp /usr/bin/phpize .
nano ./phpize
Find this line :includedir="`eval echo ${prefix}/include`/php"
...and replace it with this line :includedir="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php"
Run phpize
:./phpize
You should now see something like this :Configuring for:
PHP Api Version: 20180731
Zend Module Api No: 20180731
Zend Extension Api No: 320180731
Configure & build
We can now configure :./configure --enable-xdebug
...and run make using our custom SDK location defined as compiler flags :make CPPFLAGS='-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/main -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/TSRM -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/Zend -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/ext -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/ext/date/lib'
Might see some warning, just ignore it for now. Finally, we'll need to run :make installAgain, this command will fail because it can't move the extension to the right place. SIP will prevent it. But no worries, we'll take care of that manually at the next step. make install is still required as it will sign the *.so file.
Enabled support in PHP
Next, we move the executable somewhere safe. I use/usr/local/php/extensions
.sudo mkdir -p /usr/local/php/extensions
sudo cp /usr/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so /usr/local/php/extensions
Then we edit the PHP configuration to enable Xdebug. Simply edit php.ini
:sudo nano /etc/php.ini
And we add the following at the bottom :[xdebug]
zend_extension=/usr/local/php/extensions/xdebug.so
xdebug.remote_enable=on
xdebug.remote_log="/var/log/xdebug.log"
xdebug.remote_host=localhost
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
Restart built in server to be sure :sudo apachectl restart
And finally test everything went fine :php -i | grep "xdebug support"
If the above command returns nothing, then Xdebug is not available on your install. Go back the steps to find out what's missing.Note:
A more complete fix would be to edit the result of php-config --include-dir
, which returns /usr/include/php
. That would make any installation find the necessary header files without having to manually edit files or compiler flags.
zsh: command not found: php
I had the same issue after updating to Monterry. After some googling, I find out MacOS doesn't include PHP. You need Homebrew to install PHP again.
brew install php
https://daily-dev-tips.com/posts/installing-php-on-your-mac/
Related Topics
How to Select a MySQL Database to Use with Pdo in PHP
How to Add Filter or Hook for "Woocommerce_Add_To_Cart"
Get First Element in PHP Stdobject
Laravel 5 Auth Post Submit - Tokenmismatchexception in Verifycsrftoken.PHP Line 46
Parsing Xml Data Using PHP to Put into MySQL Database
Base64 Over Http Post Losing Data (Objective-C)
Pdo_Sqlite Driver Not Present.. What to Do
Check Image Dimensions (Height and Width) Before Uploading Image Using PHP
How to Access Magento Customer's Session from Outside Magento
How to Convert Emoji from Unicode in PHP
File_Get_Contents('Php://Input') Always Returns an Empty String
Running PHP 5.4 Built-In Web Server Outside Localhost
Getting Hour and Minute in PHP
Are There Any PHP Docblock Parser Tools Available
Composer:How to Add a Dependency Without Network Connection
How to Skip Elements in Foreach Loop
Php, How to Get Current Date in Certain Format
Pdo Prepared Statements for Insert and on Duplicate Key Update with Named Placeholders