Cubic and tetragonal perovskites from the random phase approximation