The technical expression is that pH is the negative logarithm of the hydrogen ion concentration.
What does this mumbo jumbo mean?
Chemically speaking, pure water isn't just water molecules; a very, very small, but nevertheless important proportion of any water molecules dissociate (fall apart) into their component ions.
H2O <-> H+ + OH-
This is where the water (H2O) is in equilibrium (balance) with its two ions, hydrogen (H+) and hydroxyl (OH-). These ions have an electrical charge, which is quite small, but for their size, very important.
In pure water, the concentrations of these ions are both 10-7, chemists write this as [H+] = 10-7.

Why use logarithms?

The logarithm of the number 100, which is 10 x 10, or 102 is simply "2". The logarithm of 1000 (103) is "3".
Multiplying, 100 x 1000 =100,000 or 105 , its log is, of course, "5". Multiply the numbers, but add the powers, or logarithms. Now taking ten to the power of minus something. 10-1 is 1/10 or 0.1; 10-2 = 0.01, and its log is "-2". Now the log of [H+], 10-7, is "-7", which is much easier to write than putting in all the noughts every time

Back to concentrations!

Multiplying the concentrations of the two ions in pure water

[H+] x [OH-] =10-14 (Each one is 10-7). In pure water, the hydrogen ion concentration is 10-7 , so the pH, which is the negative of the log for this concentration (-7), is +7, or simply 7.
So we can say that the pH of pure water is 7!
In any water- based solution,whether lake, river, seawater or lemonade, the product of these two concentrations is always 10-14 .

pH other than 7?

Water is a very good solvent, many things dissolve in it very easily. Pure water is something that doesn't exist for long. Distilled water is very quick to take in gases from the air and dissolve its container, given the chance. So it won't stay pure for long.

Chemicals from nature, and unfortunately in the last hundred years or so many unnatural substances, have dissolved in water to form the salt water in the world's oceans ans seas.
Rivers running into the sea dissolve some of the rocks they flow over and through, and may also take up other substances, such as humic acids from peat.
Naturally acidic water has a higher concentration of hydrogen ions than pure water, when we say that water has a pH of 5, we actually are saying [H+] =10-5 (so [OH-] =10-9).

Of more interest to marine enthusiasts, if the water is alkaline, this means that minerals in the water have set free more hydroxyl ions, or made an inbalance which has lowered the hydrogen ions. So if pH = 8, then [H+] =10-8. What should be clear is that a change of only "1" in pH value  is actually expressing a ten- fold change in the concentration of hydrogen ions! A change from pH 7 to pH 9  means a one hundred- fold change.
pH is a measure of the actual state of the water. Increases in CO2 in the night will cause a lowering of pH, which reverts to its daytime value after the lights have been on an hour or so.
To maintain a stable pH value, as in the ocean, we need to consider the effect of buffering, which is the stabilising of the pH to a constant value using substances which absorb the potential changes. But first we need to think about

measuring pH

Aquarists usually measure pH in one of two ways, electrically with a pH electrode and meter,
or with a colour test kit.
Simply stated, a pH electrode measures the number of hydrogen ions moving in the liquid, this very small signal is amplified and can be read out on a meter. This system can be very accurate, and reliable, but needs to be regularly calibrated using one (or better 2, if your meter allows it) standard solution with a fixed pH value. pH electrode behaviour changes slowly but steadily over its lifetime, until it just goes quickly off at the end and needs to be replaced. If a pH electrode is being used continuously, it should be kept clear of algal and bacterial growth, i.e. in the dark and wiped off and recalibrated weekly. This is even more important if used as a pH controller, where its output is used to switch some equipment.

Colour tests involving an indicator are basically a mixture of dyes, each of which changes its composition, and therefore colour, at particular pH values, often by direct reaction with the hydrogen ions or by loss of a hydrogen ion. Indicators do not all change colour at pH 7, some need less encouragement, some more. So by mixing the dyes, a steady set of clear colour changes can be produced for over a particular range. Other pH ranges, other dyes!