Equations of motion in curved spacetime I'm trying to understand how to use covariant actions to derive equations of motion. A simple example would be the free scalar field
$$
S = \int\;d^4x\; \sqrt{-g} \left( -\frac{1}{2}\nabla_\mu\phi\nabla^\mu\phi-\frac{1}{2}m^2\phi^2 \right)
$$
Now from classical mechanics we know that the equations of motion pop out when we set the variation of the action to zero. How would we do that in this formulation?
The $\nabla_\mu$ s represent covariant derivatives!
What I have tried:
Using the $\partial_\mu \rightarrow\nabla_\mu $ perscription the lagrangian of the free scalar field will be $$\mathcal{L} = \left( -\frac{1}{2}\nabla_\mu\phi\nabla^\mu\phi-\frac{1}{2}m^2\phi^2 \right)$$
Hence the equations of motion will come from the modified E-L equation:
$$
\frac{\partial\mathcal{L}}{\partial\phi}=\nabla_\mu\frac{\partial\mathcal{L}}{\partial(\nabla_\mu\phi)}
$$
My question is basically how do we arrive to this equation from varying the action?
 A: From Ref. 1, one sees that the Euler-Lagrange equations generalize to $$\frac{\partial \mathcal{L}}{\partial\phi}=\nabla_\mu\left(\frac{\partial\mathcal{L}}{\partial(\nabla_\mu\phi)}\right)$$
In general, when one does these things, one must make sure of two things: that the index placement is the same, and that the indexes are NOT the same in the derivative and the Lagrangian. Use the metric to raise and lower indexes as needed, and a simple relabeling will take care of the the second. Thus, I change your Lagrangian as such: $$\mathcal{L}=-\frac{1}{2}\nabla_\mu\phi\nabla^\mu\phi-\frac{1}{2}m^2\phi^2\to -\frac{1}{2}\nabla_\alpha\phi\,g^{\alpha\beta}\nabla_\beta\phi-\frac{1}{2}m^2\phi^2$$  We also note that for an object with one index, $\frac{\partial V_\alpha}{\partial V_\beta}=\delta^\beta_\alpha$. 
Thus, your scalar Lagrangian becomes
$$\begin{align}
-m^2\phi&=-\frac{1}{2}\nabla_\mu\left(\frac{\partial}{\partial(\nabla_\mu\phi)}\left(\nabla_\alpha\phi\,g^{\alpha\beta}\nabla_\beta\phi\right)\right)\\
& =-\frac{1}{2}\nabla_\mu\left(g^{\alpha\beta}\delta^\mu_\alpha\nabla_\beta\phi+g^{\alpha\beta}\nabla_\alpha\phi\delta_\beta^\mu\right) \\
&=-\frac{1}{2}\nabla_\mu\left(\nabla^\mu\phi+\nabla^\mu\phi\right)
\end{align}$$
So, finally, we have $$\nabla^\mu\nabla_\mu\phi-m^2\phi=0$$
which is just the flat spacetime version generalized by the usual prescription.
Ref. 1: Explicit gauge covariant Euler–Lagrange equation
A: I think it's more straightforward to vary the action with respect to $\phi$ and cancel surface terms. Also, check this: Derivation of Klein-Gordon equation in General Relativity
