Installation of Xdebug on MacOS Catalina 10.15 - xcode

I tried to install Xdebug on OS X 10.15 and run into following problem:
/private/tmp/pear/install/xdebug/xdebug.c:25:10: fatal error: 'php.h' file not found
I tried to fix the problem like described here: Installing xdebug on MacOs Mojave - 'php.h' file not found
Unfortunately the header files cannot be found in this directory: /Library/Developer/CommandLineTools/Packages
Any ideas where I can get the current header files for OS X 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 if xdebug.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 copy phpize 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 install
Again, 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.

If you are using brew, I solve this by reinstalling php and re-linking:
brew reinstall php#7.3
brew link --overwrite php

I got an error when I tried to install xdebug in MacOS Catalina 10.15:
pecl install xdebug-3.0.1
Error:
/private/tmp/pear/install/xdebug/xdebug.c:25:10: fatal error: 'php.h' file not found
This is due to Apple decided to remove headers file in /usr/include, like you can see in other answer.
Then I added config to .bash_profile, executing these lines in console:
echo 'export PATH="/usr/local/opt/php#7.3/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php#7.3/sbin:$PATH"' >> ~/.bash_profile
export LDFLAGS="-L/usr/local/opt/php#7.3/lib"
export CPPFLAGS="-I/usr/local/opt/php#7.3/include"
source ~/.bash_profile
After that you can try to install xdebug again with pecl:
pecl install xdebug-3.0.1
Notes: Previously I have installed PHP 7.3 with "brew". You should adjust the php and xdebug version, in the above lines, adding the versions that you prefer.

I would recommend you use "brew" to install PHP, and then use the "pecl" tool that comes with the installed version of brew's PHP to install Xdebug.

you can find detailed instructions with ready to use patches on this site: https://profilingviewer.com/installing-xdebug-on-catalina.html

Related

Local development on Mac M1 | Laravel & VueJs

I've just switched to MacOs - never used it before and I'm using Macbook M1 Pro, so a newbie here. Also, I've only started with web dev so I'm fairly new in this field as well.
Now, how should I proceed in order to set-up a local development enviroment - I plan to use mainly Laravel & VueJs?
Things I've done so far:
Installed VS code
Installe MAMP
Cloned my Git repository with project I was working on (Windows 10)
This is the part where I need help - I think I'm supposed to install Homebrew, but even if I follow the instructions on their website I can't get it working properly. It's installed but as soon as I close & reopen the terminal, it throws zsh: command not found: brew. The commands I'm used to - php artisan xyz or npm run watch don't work
Do you guys have some guide or step-by-step tutorial of what should I do in order to get my Laravel&Vue git project up & running on a localhost?
brew is installed in /usr/local/Homebrew/bin/brew (symlinked to /usr/local/bin/brew). Make sure /usr/local/bin is in your PATH, so that brew and newly installed Homebrew packages are available on the command line. This is typically setup by the ~/.zshrc file.
Troubleshooting steps:
Edit $HOME/.zshrc.
If export PATH is not found, add the following line. The important part is to ensure /usr/local/bin is present (and that :$PATH is last) to give it higher precedence. If the export PATH line exists, but commented, uncomment it.
export PATH=$HOME/bin:/usr/local/bin:$PATH
Restart your shell. .zshrc is loaded automatically at shell startup.
Check for brew with the which command:
$ which brew
/usr/local/bin/brew
Update
This suggestion here fixed my issues: https://stackoverflow.com/a/66521797/9682588
So, what I did was:
echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile

Composer error - GMP

While i want to install composer I have error:
I have installed GMP on my mac - i see it in folder + while i use "brew search gmp" i see checkmark. So its all all right.
I have also enabled in php.ini
extension=gmp.so
extension=php_gmp.so
I really don't what to do. I can't find those two files in GMP folder or anywhere in my mac. phpinfo or php -m don't see GMP loaded
Try updating your PHP version to v7.1.15 using brew install php#7.1 which should contain GMP already. They moved some stuff around recently, so the existing solutions got useless

Error installing Vim with Homebrew (checking for tgetent()... configure: error: NOT FOUND!)

After running brew install vim, I get this error:
checking for tgetent()... configure: error: NOT FOUND!
You need to install a terminal library; for example ncurses.
Or specify the name of the library with --with-tlib.
Not sure how to go about fixing this.
You need to install developer tools from Xcode before. Or set up your env handly but you might have other binaries missing later. So I recommend you to install Xcode. And then developer tools. And finally get Vim ;). I even think that Vim is installed by default with developer tools.
Get it here :
https://itunes.apple.com/us/app/xcode/id497799835?ls=1&mt=12
I ran into this problem as well. When running brew doctor, I found an ncurses5-config in the path, which seemed to be confusing homebrew. I uninstalled the chefdk, installed the latest xcode, run brew doctor to ensure the library is gone, and then run brew install vim.
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
/opt/chefdk/embedded/bin/finstyle-config
/opt/chefdk/embedded/bin/ncurses5-config
/opt/chefdk/embedded/bin/ncursesw5-config
/opt/chefdk/embedded/bin/pkg-config
/opt/chefdk/embedded/bin/xml2-config
/opt/chefdk/embedded/bin/xslt-config
This worked for me on Mac 10.11.4
brew install vim --with-tlib
You might also want to use --with-override-system-vi flag as well

Building XDebug For Use by MAMP?

I'm using MAMP on Mac OSX Mavericks. I'd like to install the latest XDebug, v2.2.4. Per the XDebug Wizard, I downloaded the XDebug 2.2.4 source. I have many versions of phpize installed on my system - one that is in /usr/bin/, and many others that come with MAMP. MAMP supplies the required phpize for each version of PHP it includes.
Seeking to use the correct phpize, per the XDebug Wizard instructions - http://xdebug.org/docs/faq#custom-phpize - I ran the phpize for PHP 5.5.3 via:
/Applications/MAMP/bin/php/php5.5.3/bin/phpize
..and got this output:
grep: /Applications/MAMP/bin/php/php5.5.3/include/php/main/php.h: No such file or directory
grep: /Applications/MAMP/bin/php/php5.5.3/include/php/Zend/zend_modules.h: No such file or directory
grep: /Applications/MAMP/bin/php/php5.5.3/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
Just in case this was not an error (since it appeared that I was following XDebug Wizard directions), I then ran configure via:
./configure --with-php-config=/Applications/MAMP/bin/php/php5.5.3/bin/php-config
...and I ran:
make
...but got this error:
fatal error: 'php.h' file not found
What is the correct way to build XDebug on OSX for use by MAMP?
Thanks very much in advance to all for any thoughts or info.
I had a similar issue and it was resolved after installing XCode and the Command Line Tools for XCode. I already had XCode installed, but I recently moved over to a new machine so I had to open it back up and it updated some things. Then I opened Terminal and ran the command...
xcode-select --install
That popped up a prompt to install the command line tools which I did and it resolved my issue.
Incase anyone else stumbles across this from Google...
My issue was the wrong phpize binary was found on the path.
I was able to resolve this using the Xdebug FAQ, specifically this section: https://xdebug.org/docs/faq#custom-phpize
When Xdebug wizard asks you to run phpize, instead find and run phpize in your MAMP directory. For me, this was:
/Applications/MAMP/bin/php/php7.1.19/bin/phpize
After this, you should see an output similar to your tailored installation instructions.
Then find and run php-config in your MAMP directory (Note: this command must be run from where you have Xdebug stored on your machine). For me, this was:
./configure --with-php-config=/Applications/MAMP/bin/php/php7.1.19/bin/php-config
You'll see a bunch of output... Followed by a, "Build complete." message.
Now you can return to your tailored installation instructions (be sure to skip the next step, Run: ./configure).
Try installing autoconf using brew : brew install autoconf

Unable to get MacPort functionality after installing Xcode 4.3

I am having trouble getting MacPorts to function properly. I just installed OSX Lion 10.7.3 I downloaded and installed MacPorts first, and then after reading the requirements, I downloaded Xcode4.3 from the App Store, and then installed it. I launched Xcode and it looks to be operational and functional. However when I attempted to port with MacPorts, it gave me this error message(excerpt):
Warning: xcodebuild exists but failed to execute
Warning: Xcode does not appear to be installed; most ports will likely fail to build.
I followed the advice from:
How do i install additional packages for Xcode on OSX Lion to allow MacPorts to work
and installed command_line_tools_for_xcode from the Preferences within Xcode. I closed Xcode, and again got the errors:
$ sudo port install libsocketsPassword:
Warning: xcodebuild exists but failed to execute
Warning: Xcode does not appear to be installed; most ports will likely fail to build.
---> Computing dependencies for libsockets
---> Dependencies to be installed: openssl zlib
---> Extracting zlib
Error: Couldn't determine your Xcode version (from '/usr/bin/xcodebuild -version').
Error:
Error: If you have not installed Xcode, install it now; see:
Error: http://guide.macports.org/chunked/installing.xcode.html
Error:
Error: Target org.macports.extract returned: unable to find Xcode
Error: Failed to install zlib
Log for zlib is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_zlib/zlib/main.log
Error: The following dependencies were not installed: openssl zlib
Error: Status 1 encountered during processing.
I am uncertain where to go next with this. How do i trouble shoot my Xcode and MacPort interface?
In theory this should work if you have Xcode4.3 installed (in /Applications):
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/
(And you've installed the optional command line tools)
Everything will start working fine after installation of "Command Line Tools for Xcode" package.
You can get it from here: https://developer.apple.com/downloads/index.action#
Please see the MacPorts migration instructions for Xcode 4.3.
The instructions are pretty involved. You need to run xcode-select to set a new tools path, update developer_dir in macports.conf (as described by Henk Poley), re-install MacPorts (ouch), and finally uninstall and re-install all of your ports (double ouch).
Edit: libpvx still wouldn't install after the above. Two extra steps were required:
sudo ln -s /Developer /
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs /SDKs
YMMV if you have different ports installed!
Also in /opt/local/etc/macports/macports.conf change the line with developer_dir to point to / instead of /Developer.
After
sudo xcode-select -switch /Applications/Xcode.app
I also had to run
sudo xcodebuild -license
and accept the licence
Here is a solution that has worked for me:
Install Command Line Tools for Xcode
Xcode -> Preferences -> Downloads
Help MacPorts find the right Xcode folder
sudo /usr/bin/xcode-select -switch /Applications/Xcode.app
Create symbolic links for clang compilers as they now live elsewhere
sudo ln -s `which clang` /Applications/Xcode.app/Contents/Developer/usr/bin/
sudo ln -s `which clang++` /Applications/Xcode.app/Contents/Developer/usr/bin/
Try using trunk, there's no release supporting Xcode 4.3 yet.
Setting the developer path in /opt/local/etc/macports.conf works for me,
developer_dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
since most of the compilers are stored there now instead of /usr/bin under Developer.
None of this works for me. Wait for macports to release a new version that officially supports XCode 4.3+
sudo mv /usr/bin/xcodebuild /usr/bin/xcodebuild.old
sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild /usr/bin/xcodebuild
Starting with Xcode 4.3, the command-line build tools are not installed by default. Launch Xcode, open the Preferences, and go to the Downloads tab. From there you should have an option to install the command-line tools.
You can also download them from the web here: https://developer.apple.com/downloads/index.action
Disclaimer: I haven't installed Xcode 4.3 yet. I have only read about it on the web.
As of 27/2/2012, the official suggestion from MacPorts seems to be to not use XCode 4.3 and instead use 4.1 through 4.2.1, which can be downloaded from Apple.
There is a bug ticket which might be useful to follow the evolution of this.
Incidentally, and as reported in my comment #11 in that bug report, I am able to build ports without warnings by using the 2 most sane-looking suggestions found in this question: sudo /usr/bin/xcode-select -switch /Applications/Xcode.app/Contents/Developer and changing developer_dir in /opt/local/etc/macports/macports.conf to /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
I have macports installed without admin/root privileges, so I was unable to test the xcode-select answers. However, I observed that Pall Melsted's answer worked, but not initially. What I found out was that I had not accepted the Xcode 4.5 license agreement!
If you have just installed Xcode for the purposes of macports, and you haven't accepted the Xcode license yet, you might get the error presented by the original post. When I checked my Xcode version using /usr/bin/xcodebuild -version, I was given the prompt to read and accept the license. After doing so, and after having made the changes suggested by Pall to the macports.conf developer_dir, it all works now.
As alternative: you can make downgrade of Xcode to 4.2.1 version. DMG of Xcode 4.2.1 placed here: https://developer.apple.com/downloads/index.action
After this MacPorts became works fine for me.
This is fixed in MacPorts 2.0.4.
To upgrade:
Download MacPorts 2.0.4 from the install site or run sudo port selfupdate.
Run the MacPorts migration described here to reinstall all ports. This is painful but required to get back to a working state.
You should definitely run sudo xcode-select -switch /Applications/Xcode.app like everyone here says, that'll fix many problems, but certainly not all.
Afaik, all the remaining problems exist within the configuration information for various packages. You might simply reinstall MacPorts as described in the migration instructions, but I found another solution.
You should begin finding all effected port files using commands like grep /Developer/ ..., after executing sudo bash and cd /opt/local naturally.
You should identify all effected ports by using port provides ..., which I piped through sed and sort | uniq. You could simply reinstall all these ports using either port -n upgrade --force ... or separate port uninstall ... and port install ... commands.
I recommend using one large port -n upgrade --force ... command to avoid duplicate rebuilds of dependencies, using the separate uninstall and install commands afterwards.
There are of course various ports for which /Developer exists only inside text config files, meaning you can fix them manually with sed -i -e 's/\/Developer//g' ..., but you cannot do so with binaries obviously.
I'm afraid you must at minimum rebuild all your Python and Perl installations, making this upgrade an ideal time to clean out packages that depend upon older versions, ala python26 and perl5.8.
There are several technically effected ports I decided against rebuilding like fuse4x-kext, who contained /Developer inside Library/Extensions/fuse4x.kext/Contents/MacOS/fuse4x but hasn't prevented sshfs from working correctly.
I had initially installed xcode 3.2.2, after which I installed 4.3. When I ran the xcode-select, I still got the same error about no xcode project in /Applications. I then dug into the /usr/bin/xcodebuild script and found out that this was working correctly, and another instance of xcodebuild (the one installed with xcode 4.3, not the one in /usr/bin) was being run and returning the error:
xcodebuild: error: The directory /Applications does not contain an Xcode project.
It seems the /usr/bin/xcode-select does not work for xcode 4.3, (it's compiled so you can't really see why it's not working). Strings doesn't give any clues. Good thing osx has strace.. oh wait.
Anyways, the best I could do was modify /opt/local/etc/macports.conf
and uncomment the line containing the path to the xcode installation. That seems to fix my problem for the most part.

Resources