Step 1:
Settings to isolate objects in your scene and get the background in Alpha, type “Transparent”:
Step 2:
Then check you have “Shadow Catcher” selected on your object settings for your ground:
Step 3:
You have to plug the alpha from the render layers as factor in the mix node
There you go !