The explanation you can find in any textbook on general chemistry, in
your local library.
As to buying an instrument, that depends on the precission you require.
They start with cheap soil pH-meters from a garden centre, and end at
4-figure laboratory instruments. Also, electrodes can be solid state
(ISFET) or glas-electrodes (which require a lot more care).