When and how did the left and right sides of a ship come to be called port and starboard?

The old Viking longboats were steered with a board (oar) that was mounted on the right side of the ship and 'steering board side' evolved into 'Starboard'. When approaching port, the steering board had to be on the side away from the landing, so it was approached on the left or "Port" side

The port side was often called 'larboard side' which evolved from loading board.

Starboard is the right hand side when stood aft and looking forward

Port is the left hand side when stood aft and looking forward