After beginning to use AirTables with PHP Curl I decided today to finally learn how to use xdebug for PHP. I’ve known for a while that my echos and vardumps were extremely inefficient compared to using a debugger… so time to sort it out!

A few things to note:

  • There are often two versions of Apache stored on MacOS. I have to use sudo /usr/sbin/apachectl restart for the desired effect rather than just apachectl
  • XDebug does not support PHP 5, so make sure you are upgraded to 7 before attempting otherwise you’ll waste a bit of time like I did.
  • Useful commands
    • php –ini
  • I went around in circles I actually had three versions of PHP on my system, but I finally ended up with 7.4 as my default.

pecl install xdebug fails

$ which pecl

$ pecl install xdebug

Build process completed successfully
Installing '/usr/local/Cellar/php/7.2.11/pecl/20170718/'

Warning: mkdir(): File exists in System.php on line 294

Warning: mkdir(): File exists in /usr/local/Cellar/php/7.2.11/share/php/pear/System.php on line 294
ERROR: failed to mkdir /usr/local/Cellar/php/7.2.11/pecl/20170718

Thanks initially to for helping me getting this fixed

To fix this error just do

rm /usr/local/Cellar/php/7.2.11/pecl
This sorts out the symlinks shenanigans, read the above blog if you want more information.

Opening PHP Config Files in VSCode

Rather than trying to use the Finder to open the configuration directory, add VSCode to the command line by ‘command shift p’ and then select Shell Command : Install code in PATH.

Then you can do this to open the folder in VSCode for easy editting.

$ /usr/local/etc/php/7.2
$ code .

Thanks initially to for the awesome blog post (again)

Basically remove the xdebug reference at the top of your php.ini since it points to the wrong place anyway.

Then, something I never knew, php will read through any ini files you put in the conf.d directory… so we put all the setup in there.

Add your XDebug Config

Create conf.d/xdebug.ini


(Change appropriate to your extension pathway, dependant on version… and also the profiler output)

(Switch profiler off when you dont need it)

php –ini should now show the xdebug bits correctly.

Setup VScode

Follow PHP Debug instructions, but basically:

Install the extension & reload

Hit gear icon in the debugging and choose php

This creates a file in .vscode/launch.json where your config is.

It didn’t work ! 🙁

So, after a bit of fiddling I realised that this laptop I am working on is still stuck in the slow lane with PHP 5.6

My php -v stated 7.2.11 but my phpinfo on my local apache was still on version 5.

I decided to upgrade to PHP 7.4 to get the latest version.

Albeit realising that I needed to upgrade my OSX !

Upgrading PHP

On upgrade success you will be told how to adjust apache configuration to point to the newer version of PHP, and not (afaik) the version (5) that got shipped with older versions of MacOS.

$ brew update
$ brew upgrade php
(Initially the upgrade failed because I had to upgrade the command line tools package through Software Update on MacOS) 
$ code /etc/apache2/httpd.conf

Comment out current version of PHP, and add

LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/

<FilesMatch \.php$>
SetHandler application/x-httpd-php

And also check DirectoryIndex looks like:

<IfModule dir_module>
    DirectoryIndex index.html index.php

Then some restarting

brew services start php
sudo apachectl restart

httpd: apr_sockaddr_info_get() failed Could not reliably determine the server’s fully qualified domain name

It turns out that many of us end up having two variants of Apache on MacOS. I have no idea why, and all I needed to actually do was use

sudo /usr/sbin/apachectl restart

And all of a sudden my phpinfo page was finally showing PHP 7.4.5 … now I could go back to the original point of trying out XDebug!

However, phpinfo() was not saying anything about XDebug which means it didnt see it being installed. This could have been the fact that I upgraded PHP after installing via PECL and so the configuration got overwritten.

So many hoops to jump through.

A quick look realised that my previous installation was of PHP 7.2, but my newer install was 7.4 so I just had to copy over the conf/xdebug.ini to the 7.4 folder and should be good to go!

After this phpinfo() showed the configuration file loading, but using php –ini I was having an image not found on the

I saw that actually for some reason my previous pecl installation of XDebug had disappeared … the old directory of 7.2 was gone!


I decided to try pecl uninstall xdebug and then pecl install xdebug and this seemed to do what I wanted. So now I could update xdebug.ini with the newer 7.4


And finally I had xdebug stuff in phpinfo() !

Using XDebug in VSCode

In debug tab, the little cog being pressed will create two options in the dropdown to its left, Listen for XDebug will listen to whatever you’ve got going on, on your local server, and the other is for specific files.

One of the things I love about XDebug straight away is navigating JSON objects … if I’ve done a json_decode I can actually navigate the object far easier than if using var_dump. Massive increase in productivity! Mission Accomplished!

Note: This blog post will be saved for all my PHP installation, configuration, and extension bits so will change over time.


How To Display Maths Equations On Websites & Apps


Javascript promises – resolve and reject continue execution of script

One thing I never knew about promises, which is actually pretty vital, is that resolve and reject from within a promise do not exit the function. Therefore if you have some code and you are resolving a promise, I used to make the fatal assumption that the function will exit at this point alongside the resolve. This can cause some serious defects in the architecture of your application if you aren’t careful.

However there’s a really simply solution. When you want resolve or reject to actually quit the function, you use ‘return resolve()’ or ‘return reject()’

Javascript essentially has this ‘run to completion’ paradigm, so unless you explicitly tell it with a return command, it will continue the script to its end point, or unless you throw an error.



Fixed my Mac Fusion Drive

Today I truly royally messed up my old iMac. It is one of the 2014 models with a 3TB fusion drive, and when I bought it second hand recently it came with Mojave OS. However, if you ever want to be able to use bootcamp for Windows – in my case I wanted to do two things – play Supreme Commander Forged Alliance occasionally AND use Amazon Lumberyard for some development in 2019. Whilst I hate Windows genuinely, begrudgingly there is always a place for it in my desktop of devices. If you have a 3TB model for some reason you can’t have bootcamp and MojaveOS on, so I needed to revert to an older OsX.

Anyway, I really messed up the disks, I was unable to partition, unable to mount, was getting mediaKit errors and could not select a hard drive to install a new OsX on. Disk Utility in Recovery Mode was refusing to be helpful and really I had just all messed it up.

Enter some googling… and I eventually found this excellent article ‘Fixing a Mac Fusion Drive that Disk Utility can’t Erase’.

I suggest you read that to be honest, but ultimately my solution was sort of simple.

  1. Open the terminal in recovery mode.
  2. Use diskutil cs list to see the drives that are there (I had several logical group volumes)
  3. Use diskutil cs delete <VOLUME_UUID> on all of them. Basically nuke the whole thing (initially I just did one of them and tried to then to do the diskutil cs create, but I got some sort of error which said there wasn’t enough space… so basically just delete everything).
  4. Exit terminal and go back into disk utility, try to do something and then was told there’s a big old error would you like to fix it?
  5. I clicked fix, and it magically sorted all life’s problems out, and I was then able to select a hard drive to install an older version of OsX on.
  6. Awesome.