Indeed you can use bitcoin-php library. A function like the following should work.
deserialize($network, $masterKey);
// Derive the child key for the given path
$segments = explode("https://bitcoin.stackexchange.com/", trim($path, "https://bitcoin.stackexchange.com/"));
foreach ($segments as $segment) {
$index = intval($segment);
$key = $key->deriveChild($index);
}
return $key->getPrivateKey()->toWif($network);
}












