How to get CiviCRM root via PHP?
I found the answer in the docs here: https://docs.civicrm.org/dev/en/latest/framework/filesystem/#tip-programmatic-lookup_1

You can use the following: 

Civi::paths()-&gt;getPath("[civicrm.root]/.")


or 

global $civicrm_root;