She was brainwashed by the Silence to kill him to stop him answering the first question on the fields of Trenzalore: "Doctor who?" The Silence believed that giving the answer would result in the return of Gallifrey & the Time Lords, reigniting the Last Great Time War.
The Silence had seen how dangerous the Doctor is so they made another (pseudo) Time Lord to use her as a weapon against him. River was brainwashed by the Silence. Despite having escaped from them in "Day of the Moon", she continued carrying out her mission to kill him in "Let's Kill Hitler", although she eventually overcame the brainwashing & used up her remaining regenerations to save his life. In "The Impossible Astronaut"/"The Wedding of River Song", she tried not to shoot him but the space suit forced her to do so.
As we discovered in "The Wedding...", it was not truly the Doctor that she shot; it was the Teselecta wearing his form (& putting on a light show to mimic regeneration). She served her prison sentence in order to convince the Silence that the Doctor had been killed but she did not, in fact, kill him.