Blackfire Setup with MAMP Pro

Blackfire Setup with MAMP Pro

Blackfire is kind of a profiler for pro users and MAMP Pro is used mostly for starters. But that doesn't mean that you're not a pro when using MAMP or that Blackfire is only useful for "professionals". It only means that there are not much resources online about how to setup Blackfire there.

In general the Blackfire documentation is quite good and also includes a description how to do a manual installation. Unfortunately it misses one part which through me off at the beginning.

First of all, check if you've configured your MAMP to use a separate php.ini (one for Apache and one for the console). This is important if you also want to run blackfire on the console. I have php symlinked to use the MAMP version in iTerm and the specific php.ini in my profile.

alias php="/Applications/MAMP/bin/php/php7.3.8/bin/php -c /Applications/MAMP/bin/php/php7.3.8/conf/php.ini"

In the documentation you find the probe, but you won't find the file. The best way to download that is to use homebrew with the following command:

brew install blackfire-php73 --without-homebrew-php

Replace php73 with whatever version you're using. This will result in the file to be installed to /usr/local/Cellar/blackfire-php73/1.27.1/ (depending on the version the path will change, but you get the gist). Change into the director and copy the to your extension directory with:

cp /Applications/MAMP/bin/php/php7.3.8/lib/php/extensions/no-debug-non-zts-20180731/

Now put the following configuration with your api key and secret (the ones you get from Blackfire) at the end of your php.ini. If you use the MAMP templates, add it there.

;Replace with your extension path (different for every php version)

; Socket for Mac
blackfire.agent_socket = unix:///usr/local/var/run/blackfire-agent.sock

blackfire.agent_timeout = 0.25

blackfire.log_level = 4
blackfire.log_file = /tmp/blackfire.log

blackfire.server_id = {your-server-id}
blackfire.server_token = {your-server-token}

Verify that the extension is installed through running

php --ri blackfire

You should be good to go. I recommend to add another alias for Blackfire to use the full php path including configuration so that you don't have to run it the following way:

blackfire run /Applications/MAMP/bin/php/php7.3.8/bin/php -c /Applications/MAMP/bin/php/php7.3.8/conf/php.ini bin/console app:your-command