Building and installing Xdebug on Mac OS X with MAMP
Asked Answered
T

5

10

I'm having a problem building and installing Xdebug on Mac OS X with MAMP.

I searched online extensively so far and at the moment I am stuck on the part of Xdebug "Installation Wizard" that tells me to "Run: phpize" on the source code I downloaded.

When I run phpize I get the following message:

new-host-2:xdebug-2.2.0 Dima$ phpize

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:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

If I do a which phpize I get:

new-host-2:xdebug-2.2.0 Dima$ which phpize
/usr/bin/phpize

This is not the version I want to use. I want to use the MAMP installed version of phpize I assume since I want to install Xdebug on the MAMP version of PHP. This is puzzling because I added the MAMP specific PHP bin path to my .bash_profile already into the $PATH variable.

If I run echo $PATH I get:

new-host-2:xdebug-2.2.0 Dima$ echo $PATH

/opt/local/bin:/opt/local/sbin:/Applications/MAMP/bin/php/php5.4.3/bin:/Users/Dima/.rvm/gems/ruby-1.9.2-p290/bin:/Users/Dima/.rvm/gems/ruby-1.9.2-p290@global/bin:/Users/Dima/.rvm/rubies/ruby-1.9.2-p290/bin:/Users/Dima/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

The MAMP-specific PHP path shows up ahead of '/usr/bin'. The next thing I tried was running the MAMP-specific phpize providing it the entire path manually like so:

new-host-2:xdebug-2.2.0 Dima$ /Applications/MAMP/bin/php/php5.4.3/bin/phpize
-bash: /Applications/MAMP/bin/php/php5.4.3/bin/phpize: Permission denied

Now I checked for permissions on these files in Finder and it shows that I have full permission to read and write the files this folder. I am a little lost.

Twitty answered 8/7, 2012 at 1:2 Comment(0)
R
16

I had the same problem, but I found a better solution.

Xdebug is already in MAMP.

Check your php.ini file:

/Applications/MAMP/conf/php5.x/php.ini

Go all the way down. You will see

[xdebug]
;zend_extension="/Applications/MAMP/bin/php5.X/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"

Change that into

[xdebug]
zend_extension="/Applications/MAMP/bin/php5.X/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_handler=dbgp

Restart the server... Done!

See: Want to run Xdebug? MAMP is the easiest way…

Royce answered 29/1, 2013 at 21:14 Comment(5)
Indeed. XDEBUG is already ready to use with MAMP (at least PRO version)Hyaline
Even with the non-pro version, this solution works! So much simpler, thanks for your instructions! :DBibelot
For my case, it was found under: /Applications/MAMP/bin/php/php7.X/lib/php/extensions/no-debug-non-zts-20160303/xdebug.soWilmerwilmette
You can find which php.ini file to load by checking MAMP's start page, and then going to "Tools->phpinfo" and looking at the value for "Loaded Configuration File"Bal
These xdebug 2 instructions no longer work for xdebug3.Ledbetter
M
8

I tried the Dmitry Samuylov's answer, and it didn't quite work for me, so I googled some more and here's what did the trick.

  1. Download and unpack the MAMP Components from SourceForge

  2. Make a note of the path(s) that were not found during the phpize process. For me it was:

    /Applications/MAMP/bin/php/php5.2.17/include/php/main/php.h
    
    /Applications/MAMP/bin/php/php5.2.17/include/php/Zend/zend_modules.h
    
    /Applications/MAMP/bin/php/php5.2.17/include/php/Zend/zend_extensions.h
    
  3. Create the required path in your MAMP PHP directory. Again for me it was

    /include/php/
    
  4. Ensure the correct permissions on the directory

  5. Find the components for your target PHP version (in my case 5.2.17) and copy them into the path you created in step 3.

  6. Run the instructions for using the correct version of phpize from the Xdebug site

Moiramoirai answered 4/10, 2012 at 12:25 Comment(3)
Any suggestions on where to 'Find the components for your target PHP version)?Median
To find those files, download the PHP source. i.e for 5.4 use this link: us2.php.net/get/php-5.4.4.tar.gz/from/a/mirror . You can extract and dump the entire thing in the /Applications/MAMP/bin/php/php5.2.17/include/php/ made in step 3, or just the file required. either will work!Median
@Median not needed for MAMP, it is allready included.Ledbetter
T
3

After more research and trial and error I managed to install it after doing the following things:

  1. In Terminal, I ran chmod u+x /Applications/MAMP/bin/php/php5.4.3/bin/*. To open execute permissions on phpize and everything else in that path
  2. Following this article to install command line tools
  3. Following this article to install the latest Autoconf and related tools
  4. After that, following the steps provided by the Xdebug Wizard worked without a hitch
Twitty answered 8/7, 2012 at 3:53 Comment(0)
L
1

It's important to point out that the instructions in the "solution" are for Xdebug 2. We are at Xdebug 3 these days.

Xdebug 3 on MAMP / macOS

To enable Xdebug 3 in MAMP on macOS, do this:

  • Open Tools → phpinfo

  • Locate the line Loaded Configuration File and copy the complete path (/Application/MAMP/......) of the php.ini file.

  • Open a Terminal and type the command open and paste the copied complete path of the active php.ini file.

  • Add the following lines

    [xdebug]
    zend_extension = xdebug
    xdebug.mode = debug
    xdebug.show_local_vars=1
    
  • Restart the MAMP web server.

Check

Check phpinfo again (refresh) and lookout for a line under ZEND engine starting with Xdebug vX.X.X..... Further down you will find a section with the big Xdebug logo that shows you the version and what is (dis|en)abled.

If this doesn't appear, check for spelling mistakes, or other typos.

Consult the Xdebug documentation for additional settings which can be added at the php.ini file you opened like for instance profile. If you change the PHP version, you will have to repeat the procedure.

Alternative

Alternatively, buy a MAMP Pro license that allows to do this from the MAMP control panel.

Additional steps

In order for the debugger (or profiler) to start you will need to add a magic cookie in browser requests. You can add these easily with a browser plugin like "Xdebug helper" for Chrome.

Ledbetter answered 30/11, 2022 at 10:48 Comment(0)
D
0

It’s easy.

In the *C:\MAMP\conf\php x.x.x * directory, open each php.ini related.

And then just put these lines in php.ini:

[xdebug]

xdebug.default_enable=1

xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1

zend_extension="C:\MAMP\bin\php\php5.5.0\ext\php_xdebug.dll"
Distaste answered 29/12, 2014 at 8:4 Comment(1)
Hey Ramin, just from your answer it looks like you're offering a solution for windows, the question has always been Mac OS X specific, even says so in the question title.Twitty

© 2022 - 2025 — McMap. All rights reserved.