Making use of the sol-gel technique, an optical pH sensor was prepared, which was made from an organic carrier with four indictors including congo red, bromophenol blue, cresol red, and chlorophenol red, cross-linked by tetraethyl orthosilicate (TEOS) and cellulose acetate. The actual detection range of the optical pH sensor is 2.5–11.0. The optimal ratio of ethyl orthosilicate, absolute ethanol, deionized water, and hydrochloric acid in glue precursor of the sensor-sensitive membrane was explored. The orthogonal experiment was designed to optimize the dosage of cellulose acetate, N,N-dimethylformamide (DMF), indicator, hydrochloric acid, and precursor glue in preparing the sensor-sensitive membrane. The linearity, measurement accuracy, repeatability, stability, and response time of the prepared pH sensor were tested. The measurement results were analyzed using a support vector machine and linear regression. The experimental results show that the optical pH sensor has a measurement accuracy of up to 0.2 pH and better stability and repeatability than the traditional pH glass electrode.