In this research, treatment of a pharmaceutical wastewater (PhW) obtained from a factory by electro‐Fenton (EF) and photoelectro‐Fenton (PEF) processes was investigated. The effects of several parameters involving pH, current density, H2O2/Fe2+ molar ratio, volume ratio of H2O2/PhW, UVA light, and time were studied. The experiments were designed by Design Expert software, and response surface methodology (RSM) was applied to determine the optimum conditions for the highest COD removal. According to the analysis of variance (ANOVA), time was the most significant parameter on the process response (COD removal) followed by current density. The optimal conditions for 86.85% of COD removal through the EF process were at pH of 2.96, current density of 42.90 mA/cm2, H2O2/Fe2+ molar ratio of 3.78, volume ratio of H2O2/PhW of 1.37 ml/L, and reaction time of 58.49 min, while the optimal conditions for 93.00% of COD removal through PEF process were at pH of 2.91, current density of 43.71 mA/cm2, H2O2/Fe2+ molar ratio of 4.29, volume ratio of H2O2/PhW of 1.67 ml/L, UVA light of 6 W, and reaction time of 54.24 min. It was concluded that UVA light can increase the COD removal through PEF process around 7% more than that of the EF process at optimum conditions.