Settings up xdebug on MAMP PRO
Asked Answered
F

2

23

I am trying to set up xdebug on mamp pro with no success. I searched all over the internet, nothing helped me.

First I have tried just to uncomment the following line in php.ini:

zend_extension="/Applications/MAMP/bin/php/php5.4.4/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so"

Next, I've tried the wizard: http://xdebug.org/wizard.php

Next, I've tried adding these lines to php.ini:

xdebug.default_enable=1

xdebug.remote_enable=1

xdebug.remote_handler=dbgp

xdebug.remote_host=localhost

xdebug.remote_port=9000

xdebug.remote_autostart=1

Nothing helps. I can't see xdebug in my phpinfo.

MAMP PRO Version: 2.1.1

PHP Version: PHP 5.4.4

Thanks!

Florio answered 23/7, 2012 at 18:19 Comment(1)
If you have the pro version in the control panel under PHP there should be a [Activate Xdebug in about the middle of the screen] (i.sstatic.net/dM0fV.png)Splashy
F
32

Since release of MAMP 2.01 XDebug is already included.

Solved. Here's the tutorial that helped me:

  1. Start MAMP

  2. Edit php.ini template file through MAMP to enable the extension. Edit the template file via File -> Edit Template -> PHP -> PHP php.ini

    edit php.ini template for mamp on mac osx

  3. Edit bottom of php.ini template file so that it ends up looking like if you want profile output

    [xdebug]
    zend_extension="/Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"
    xdebug.profiler_enable = 1
    xdebug.profiler_output_dir = "/tmp"
    ; DONT REMOVE: MAMP PRO php5.3.6.ini template compatibility version: 1
    

    If you don’t want profile output and just want xdebug running then use

    [xdebug]
    zend_extension="/Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"
    xdebug.profiler_enable = 0
    xdebug.profiler_output_dir = "/tmp"
    ; DONT REMOVE: MAMP PRO php5.3.6.ini template compatibility version: 1
    

    Now when you have errors, if they are sent to standard out, you will see something like this

    My php.ini file:

    edited php.ini file to run xdebug on mamp mac osx

  4. Save edited template and close edit window

  5. Restart MAMP

  6. Open MAMP’s WebStart page and navigate to PHPInfo tab. Check to make sure that Xdebug is running. Doing a search in the browser window for “Xdebug” makes this easy.

    confirm xdebug running on mamp on mac osx

  7. If you used the same settings that I have above, when you run PHP code, Xdebug will put the cachegrind.out files in your ‘/tmp’ directory. Open your ‘/temp’ directory and run one of your PHP files to make sure it is working correctly. You can open the ‘/tmp’ directory in finder by opening the terminal and running

    open /tmp
    

    cachegrind.out output in /temp folder for mamp on mac osx

  8. Now you can use any app that understands those cachegrind.out files to view the profile data. Apps like KCacheGrind (Linux/Windows, KDE), WinCacheGrind (Windows), xdebugtoolkit, and Webgrind.  I went the simple route and used webgrind. Webgrind is a simple web based application that you can run locally on MAMP and it will look for the cachegrind.out files automatically with just one click. Continue for steps on setting up with webgrind.

  9. Download Webgrind

  10. Setup Webgrind host on MAMP to run Webgrind

    Setup webgrind as host on mamp to process xdebug php profile output

  11. Visit webgrind url setup on your local MAMP installation. Mine was simply webgrind/

  12. If you already have cachegrind output files you should be able to select the file in the “Auto (newest)” dropdown or leave it select at Auto and click update which will reveal the profile data

  13. Throw a celebratory fist pump

Florio answered 23/7, 2012 at 21:36 Comment(8)
@note: the file must edited from MAMP menu. Editing this from FINDER is useless @_@Owades
Thanks for the link. But I'm worried it may go offline in the future and then this answer will be useless.Contributory
In case @ChrisHarrison's worries come to pass, here is the short story: MAMP (pro or not) comes with xdebug installed, so all you need to do to enable it is uncomment a line in the php.ini. It's usually around the last line, but you can search for [xdebug].Sclerosed
Oh, and if you edit the file directly, the path is /MAMP/bin/php/php<version>/conf/php.ini. And don't forget to restart the servers afterwards.Sclerosed
Since 3.0.? version in PHP Tab you can see: Debugger - Activate XDebugBurmese
@Burmese I have MAMP PRO 3.0.7.3 and have enabled Xdebug on the PHP tab and still can't get Codebug nor the old MacGDBp to connect. MacGDBp reports "Could not open socket." Do you have any more recent directions on how to get this going?Acclaim
@ChrisHarrison the link is not going anywhere anytime soon :)Liuka
If you want to see the call graph of your code, there is also a premium native mac alternative to webgrind: Profiling ViewerHardtack
D
1

I had trouble with setting up MAMP Pro and nginx myself and the above answer did not work for me.

The problem was that the default port setting is 9000, which in my case I have that port already in use so I looked in my nginx conf at this line:

location ~ \.php$ {
            try_files        $uri =404;
            fastcgi_pass     unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI.sock;
            fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include          fastcgi_params;
        }

then go to the file located when fastcgi_pass is set to, and in there you will find the correct port number. In my case it was in Applications/MAMP/Library/logs/fastcgi and the filename is dependent on your host's php version.

Then open that file, and set whatever PID is in there to xdebug.remote_port in php.ini, for me it was 13267.

It may be worthwhile to mention my MAMP config for PHP is set to CGI mode, not modules.

EDIT:

I just realized that the port number dynamically changes way too much. So I set a hardcoded value for fastcgi pass in my nginx template for MAMP like so:

fastcgi_pass      127.0.0.1:9072;
# comment out the regular setting just in case.
# fastcgi_pass     unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI.sock;
Deuteranope answered 24/6, 2019 at 14:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.