Despite several attempts to enhance the electrical and charge carrier transport characteristics of porous silicon (PSi), the requisite conditions for optimally synthesizing n-PSi with appealing optoelectronic properties are yet to be achieved. Therefore, this research explores the effect of the chemical ratio of precursor materials (HF:C2H6O:H2O2) on the surface morphology, crystalline structure, and optical and electric properties of PSi. The PSi was produced by photoelectrochemical etching followed by anodization of the n-type Si under light illumination. The properties of the as-prepared PSi were studied by means of microscopic and spectroscopic techniques. The HF:C2H6O:H2O2 chemical ratio was optimized at 2 : 1 : 1. A metal–semiconductor–metal (MSM) ultraviolet photodetector (Pt/n-PSi/Pt) was fabricated, which exhibited high performances under UV light (365 nm) illumination. The photodetector was shown to be highly stable and reliable with a rapid rise time of 0.56 s at a bias voltage of +5 V. The MSM photodetector displayed responsivity (Rp) of 9.17 A/m at 365 nm, which significantly exceeds the values reported for TiC/porous Si/Si in some contemporary research. The photodetector fabricated from n-PSi, synthesized at an optimum chemical ratio (2 : 1 : 1) exhibited the best photodetection performance, possibly due to the high porosity and defect-free state of the n-PSi thin films.