  We apply the derivative expansion approach to the Casimir effect for a real
scalar field in $d$ spatial dimensions, to calculate the next to leading order
term in that expansion, namely, the first correction to the proximity force
approximation. The field satisfies either Dirichlet or Neumann boundary
conditions on two static mirrors, one of them flat and the other gently curved.
We show that, for Dirichlet boundary conditions, the next to leading order term
in the Casimir energy is of quadratic order in derivatives, regardless of the
number of dimensions. Therefore it is local, and determined by a single
coefficient. We show that the same holds true, if $d \neq 2$, for a field which
satisfies Neumann conditions. When $d=2$, the next to leading order term
becomes nonlocal in coordinate space, a manifestation of the existence of a
gapless excitation (which do exist also for $d> 2$, but produce sub-leading
terms).
  We also consider a derivative expansion approach including thermal
fluctuations of the scalar field. We show that, for Dirichlet mirrors, the next
to leading order term in the free energy is also local for any temperature $T$.
Besides, it interpolates between the proper limits: when $T \to 0$ it tends to
the one we had calculated for the Casimir energy in $d$ dimensions, while for
$T \to \infty$ it corresponds to the one for a theory in $d-1$ dimensions,
because of the expected dimensional reduction at high temperatures. For Neumann
mirrors in $d=3$, we find a nonlocal next to leading order term for any $T>0$.
