Installing xdebug with laravel valet and php 7.2 on Mac, and linking with PHPStorm

Hassaan Sadiq
Oct 30, 2018 · 2 min read
  1. Install or update Homebrew to the latest version

brew update.

2. Install PHP 7.2

brew install php@7.2.

Make sure Mac is using the lastest version of php which you installed using homebrew. php -v should show

PHP 7.2.11 (cli) (built: Oct 11 2018 16:23:09) ( NTS )

Copyright © 1997–2018 The PHP Group

Zend Engine v3.2.0, Copyright © 1998–2018 Zend Technologies

with Xdebug v2.6.1, Copyright © 2002–2018, by Derick Rethans

with Zend OPcache v7.2.11, Copyright © 1999–2018, by Zend Technologies

3. Install the xdebug

pecl install xdebug . You won’t be able to install xdebug using homebrew.

Make sure php -m is showing Xdebug in [Zend Modules] and xdebug in [PHP Modules].

4. Edit the xdebug settings in php.ini

Find the path of php using which php . For me it was /usr/local/bin/php, so will use it next, replace it with your path for next commands.

Cd into cd /usr/local/bin/php/7.2/conf.d and edit ext-xdebug.ini file, it its not available, create it and paste following in it.

[xdebug]

xdebug.remote_autostart=1

xdebug.remote_port=9001

xdebug.remote_host=127.0.0.1

xdebug.remote_connect_back=1

xdebug.default_enable=1

xdebug.default.idekey=PHPSTORM

Run php -i | grep xdebug and verify that xdebug variables whcih you mentioned above are reflecting the correct values.

5. Rest of Valet installation.

If valet is already installed, restart it.

Otherwise.

Install Composer.

Install Valet with Composer via composer global require laravel/valet. Make sure the ~/.composer/vendor/bin directory is in your system's "PATH".

Run the valet install command. This will configure and install Valet and DnsMasq, and register Valet's daemon to launch when your system starts.

Sometimes the order of valet installation is also important. For example if you first installed valet, and then updated php or its settings, it might not pick up things. So you might have to uninstall the valet and re-install according to the order given in article.

6. Linking with PHPStorm

Open PHPStorm, goto preferences => Lanuages & Frameworks => PHP => Debug and make all settings like this screen. Apply

Goto preferences => Lanuages & Frameworks => PHP => Debug => DBGp Proxy and make all settings like this screen. Ok

7. DEBUG — YEEEAAAHHHH

Add a breakpoint somewhere, and open the valet based *.test url. It should auto stop breakpoint. No need to provide XDEBUG_PHPSTORM keys or installing xdebug extensions.

Helpful resource

https://www.youtube.com/watch?v=iSSjeelN5NU

Hassaan Sadiq

Written by

CTO, Co-founder at GrocerApp (Pakistan’s largest online grocery startup)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade