Equations of motion from Lagrangian I have the action
$$S=\int d^4x\sqrt{-g} \Big[\frac{1}{8}\phi^2R- \frac{1}{2}g^{\mu\nu}\partial_\mu\phi\partial_\nu\phi - \frac{1}{2}m^2\phi^2\Big]$$
where $\phi$ is a scalar field and $R$ is the scalar curvature (signature $-+++$)
I want to get the equations of motion and then substitute in the FRW metric.
Could someone show me how to vary this action?
Alternatively could I simply substitute the FRW metric into the above action and then calculate the Euler-Lagrange equations for the scale factor $a(t)$ and the scalar field $\phi$?
I guess in that case I would only get two equations rather than the three I would get by substituting the FRW metric into the full equations of motion.
 A: You vary the action with brute force Variation for simplicity. I assume that you can handle the last two terms and the problem is the first one. Varying with respect to $\phi$ you'll obtain:
$$\Box \phi + \cfrac{1}{4}R\phi -m^2 \phi =0$$
Varying with respect to the metric you have to integrate by parts the first term.
$$\delta(\phi ^2 R) = \phi^2 \delta R = \phi^2 (g_{\mu\nu}\Box \delta g^{\mu\nu} - \nabla_{\mu} \nabla_{\nu}\delta g^{\mu\nu} + R_{\mu\nu}\delta g^{\mu\nu})$$
You want $\delta g^{\mu\nu} $ to be a multiplying factor so you integrate by parts twice and now the derivatives will act on $\phi^2$.
For the integration check my answer here: Derivation of $f(R)$ field equations, problem with integration by parts
Τhe final answer will be:
$$ \cfrac{1}{8}\left( g_{\mu\nu}\Box - \nabla_{\mu}\nabla_{\nu} + G_{\mu\nu}\right)\phi^2 - \cfrac{1}{2}\nabla_{\mu}\phi\nabla_{\nu}\phi + \cfrac{1}{4}g_{\mu\nu}\nabla^{\xi}\phi\nabla_{\xi}\phi + \cfrac{1}{4}g_{\mu\nu}m^2\phi^2=0$$
You will obtain $4$ Einstein's equations and one Klein-Gordon. Only two of them are independent though. You can of course plug in the metric and vary with respect to the scale factor. The result will be the same. If you want to vary the action by hand and then use a program to obtain the components of equations, varying with respect to the field surely contains less manipulations than varying with respect to the scale factor $a$.
