In general relativity one can derive the Einstein Field Equations by the principle of least action through variations with respect to the inverse of the metric tensor. In some modified theories of gravity, such as the Brans-Dicke Theory, a scalar field is added to the Einstein Hilbert Action and the gravitational constant is replaced by a function of the scalar field. I am not quite sure how to derive the field equations from this action, more specifically the part where the scalar field is attached to the Ricci scalar $\phi R$.
The Brans-Dicke Action is $$S_{BD} = \int d^4x \sqrt{-g}\left[ \frac{1}{16\pi}\left(\phi R - \frac{\omega }{\phi}g^{ab} \partial _a\phi\partial _b \phi \right) +L_M \right].$$
The resulting field equation is $$G_{ab} = \frac{8\pi}{\phi}T_{ab}+\frac{\omega}{\phi^2} (\partial_a\phi\partial_b\phi-\frac{1}{2}g_{ab}\partial_c\phi\partial^c\phi) +\frac{1}{\phi}(\nabla_a\nabla_b\phi-g_{ab}\Box\phi).$$
I also want to derive a new field equation for practice. So my questions are:
How does one derive the equations of motion?
How to perform the variation of the following action? $$S=\int d^4x \sqrt{-g} \left[ \frac{1}{16\pi G} R - \phi( \nabla_{\mu} g_{ab} \nabla_{\nu}g_{ab}) - 2\Lambda+L_M) \right] $$
The Ricci scalar, the cosmological constant, and the matter Lagrangian will variate simply like the Einstein Hilbert Action to: $$\delta S = \int d^4x \sqrt{-g} \left[ \frac{1}{\kappa} \left( R_{ab}-\frac{1}{2}Rg_{ab}+\Lambda g_{ab} \right) -T_{ab} \right]\delta g^{ab}.$$ What about the extra term? Would one simply variate with respect to $\phi$, or is the variation of the covariant derivative of the metric tensor also required? If the latter is true, then would the variation of this extra term be $$\frac{\partial L}{\partial g_{ab}}-\partial _\mu\frac{\partial L}{\partial (\nabla_{\mu}g_{ab})}=0.$$ Any help would be appreciated. By the way, is $\nabla_{\mu}g_{ab}\nabla_{\nu}g_{ab}$ an expression that shows the rate of change (derivative) of the metric tensor with respect to a coordinate $(t, x, y, z)$?