A porous P, K co-doped g-C3N4 photocatalyst was successfully synthesized under vapor and a self-producing NH3 atmosphere by a handy one-step method for the first time. During thermal polymerization, the vapor generated from the residual water and self-producing NH3 was used as the reaction atmosphere, leading to the improvement of the specific surface area and a downshift of the band alignments. Moreover, K2HPO4, as a dual-functional modifying agent, enabled not only K-doping but P-doping. This could increase the degree of crystallization to improve the efficiency of electronic transmission, reduce the energy of bandgaps to improve the light adsorption ability, and increase the potential of the valence band to enhance its oxidation capacity, resulting in an enhanced photocatalytic performance. The degradation of RhB was employed to study the photocatalytic activities, and the results could be fitted by zero-order kinetics. The reaction rate of the optimal co-doped g-C3N4 was 2.7 times that of pure g-C3N4. Cycling experiments were implemented to study the stability. Furthermore, the photocatalytic mechanism was explored by trapping experiments, and the results were consistent with the band structures deduced by the X-ray photoelectron spectroscopy (XPS) and UV–Vis profiles.