In recent years, organic-inorganic hybrid perovskites have attracted wide attention due to their excellent optoelectronic properties in the application of optoelectronic devices. In the manufacturing process of perovskite solar cells, perovskite films inevitably have residual stress caused by non-stoichiometry components and the external load. However, their effects on the structural stability and photovoltaic performance of perovskite solar cells are still not clear. In this work, we investigated the effects of external strain on the structural stability and optoelectronic properties of tetragonal MAPbI3 by using the first-principles calculations. We found that the migration barrier of I- ion increases in the presence of compressive strain and decreases with tensile strain, indicating that the compressive strain can enhance the structural stability of halide perovskites. In addition, the light absorption and electronic properties of MAPbI3 under compressive strain are also improved. The variations of the band gap under triaxial and biaxial strains are consistent within a certain range of strain, resulting from the fact that the band edge positions are mainly influenced by the Pb-I bond in the equatorial plane. Our results provide useful guidance for realizing the commercial applications of MAPbI3-based perovskite solar cells.