We present a gauge invariant approach to photoproduction of mesons on nucleons within a chiral unitary framework. The interaction kernel for meson-baryon scattering is derived from the chiral effective Lagrangian and iterated in a Bethe-Salpeter equation. Within the leading order approximation to the interaction kernel, data on kaon photoproduction from SAPHIR, CLAS and CBELSA/TAPS are analyzed in the threshold region. The importance of gauge invariance and the precision of various approximations in the interaction kernel utilized in earlier works are discussed.