Recent experiments on chemical tuning of spacer cations (phenylethylammonium: PEA) with electronegative entities such as Cl or F in 2D-3D Ruddlesden-Popper (RP) perovskite layers show simultaneous improvement in their device performance and stability. In order to understand the role of such substitution on the properties and stability of 2D and 2D-3D layers of PEA2PbI4 with engineered spacer cations, here we present results of state-of-the-art ab initio calculations. It is found that Cl and F substitution in spacer cations does not affect much the inorganic framework but increases the stability of the layered compounds. This enhancement in stability is attributed to strong van der Waals interactions particularly in the case of Cl substitution. Moreover, a rotation of the phenyl ring does not significantly affect the electronic and optical properties of the 2D-3D RP perovskite layers. However, the chemical tuning of PEA spacer cations results in a moderate blue shift in the optical absorption spectra. Further study on F- and Cl-substituted PEA2PbBr4 layers show their better stability than in the case of iodides and the possibility of applications in blue light-emitting diodes. Our results are in very good agreement with the available experimental findings and pave the way toward a better understanding of the more stable RP perovskite layers for photovoltaic and optoelectronic applications. ©