- Port 9001 was chosen above as Valet tends to use 9000 also. We now need to reconfigure PhpStorm to list on this port. Open preferences and type xdebug into the search box. Then find Languages & Frameworks - PHP - Debug on the left hand navigation pane and change the port to 9001. That’s pretty much it for PhpStorm.
- How to Debugging PHP with VS Code Summary basic spec instruction MacOS 1. Setup nginx install xdebug 4. Start php-fpm and nginx 5. Test Windows Linux Ubuntu 17.04 1. Install packages 2. Enable Xdebug 4. Start attach running.
Recently there have been a lot of changes to Homebrew in that there have been a number of packages renamed and improved. One of the packages that have been affected it PHP.
Xdebug is a must-have extension for PHP, although sometimes you need to toggle it to make things faster. XDebugToggler.app for macOS allows you simply toggle xDebug on and off. You can also restart system some services while toggling like PHP, Nginx, MySQL that you can choose on the application settings. If you just work on CLI scripts like testing, you shouldn't need to restart any system. You can install Xdebug through PECL on Linux & macOS with Homebrew. Run: pecl install xdebug On Apple M1 hardware, you might instead need to use: arch -x8664 sudo pecl install xdebug Warning: You should ignore any prompts to add 'extension=xdebug.so' to php.ini — this will cause problems.
Specifically renaming the php71
to php@7.1
, this has caused some confusion amongst the community on how to install PHP on Mac OSX and to enable xdebug
.
In this post we will walk through the process of cleaning up a current installation of PHP on Mac OSX using Homebrew and enabling xdebug
If you have previously installed PHP on your Mac OSX using Homebrew you may want to take this opportunity to clean up your installation and reconfigure your machine with the latest packages.
Clean up old installs of PHP
We will use HomeBrew to install PHP 7.2 using the new Taps available. We will go ahead and uninstall all versions of PHP to ensure we only will have PHP installed via Homebrew.
First lets examine what PHP packages have been installed
Brew Xdebug-osx
We can now uninstall any packages that have been installed
Ensure we remove any old casks in Homebrew
Clean up all the launch agents to ensure there is no confusion later on.
We can now ensure Homebrew is cleaned up and updated
Check to see if there are any daemons running. If there are then reboot
Install PHP using Homebrew
By default this will install PHP 7.2.x (or whatever the latest edition of PHP is when you install it)
You will now be able to write and run applications using PHP. However, if you would like to be able to debug your PHP applications there are some additional steps you need to complete to install xdebug
.
What is xdebug ?
Xdebug is an extension for PHP to assist with debugging and development. It contains a single step debugger to use with IDEs; it upgrades PHP’s var_dump()
function; it adds stack traces for Notices, Warnings, Errors and Exceptions; it features functionality for recording every function call and variable assignment to disk; it contains a profiler; and it provides code coverage functionality for use with PHPUnit.
Prior to moving the PHP taps in Homebrew it used to be possible to install xdebug and PHP7.2 at the same time using brew install php72-xdebug
, sadly this is not the case, and from what I understand this won’t be happening anytime soon.
PECL (PHP Extension Community Library) is now the source of xdebug and all future updates will available via PECL
How to install xdebug on Mac OSX
Installing xdebug via PECL is fairly straight forward, because if you have PHP7.2 installed you should be able to update your channel list first
This will check whether you already have xdebug
installed
If xdebug is not install you can simply install it using
if you want to upgrade xdebug to the latest version simply
Configure PHP to use xdebug
We need to add the following line to .
To find out where your php.ini file is
Which should return something similar too:
Configure PHP.ini
You can open the file using
The search for the
Then change it too
The additionally update the following
Brew Xdebug 2020
Configure PHPStorm
We predominantly use PHPStorm – Lightning-smart PHP IDE as our default PHP Development editor.
So it is worhtwhile ensuring you have enabled xdebug in PHP storm as your debugger – Xdebug Installation Guide
Summary
You should now have a complete PHP Development Environment configured on your Macbook.
- Book Review: Building Event-Driven Microservices - April 23, 2021
- Implementing logging with Serilog - April 17, 2021
- Getting started with .net core microservices with dapr - April 11, 2021