Graphitic C3N4-based materials are promising for photocatalytic H2 evolution applications, but they still suffer from low photocatalytic activity due to the insufficient light absorption, unfavorable structure and fast recombination of photogenerated charge. Herein, a novel anion–cation co-doped g-C3N4 porous nanotube is successfully synthesized using a self-assembly impregnation-assisted polymerization method. Ni ions on the surface of the self-assembly nanorod precursor can not only cooperate with H3P gas from the thermal cracking of NaH2PO2 as an anion–cation co-doping source, but, more importantly, suppress the shape-collapsing effect of the etching of H3P gas due to the strong coordinate bonding of Ni-P, which leads to a Ni and P co-doped g-C3N4 porous nanotube (PNCNT). Ni and P co-doping can build a new intermediate state near the conduction band in the bandgap of the PNCNT, and the porous nanotube structure gives it a higher BET surface area and light reflection path, showing a synergistic ability to broaden the visible-light absorption, facilitate photogenerated charge separation and the light-electron excitation rate of g-C3N4 and provide more reaction sites for photocatalytic H2 evolution reaction. Therefore, as expected, the PNCNT exhibits an excellent photocatalytic H2 evolution rate of 240.91 μmol·g−1·h−1, which is 30.5, 3.8 and 27.8 times as that of the pure g-C3N4 nanotube (CNT), single Ni-doped g-C3N4 nanotube (NCNT) and single P-doped g-C3N4 nanotube (PCNT), respectively. Moreover, the PNCNT shows good stability and long-term photocatalytic H2 production activity, which makes it a promising candidate for practical applications.