How difficult is it to organise live performances?

I recently watched the Only Fools and Horses musical which is currently running in the UK and as far I can see the performance ran flawlessly. An advantage with TV and film is that a scene can be reshot if something goes wrong eg forgetting lines but that is not available in a live performance and it would be embarrassing if someone forgot their lines in a play. In TV and film something is recorded once and doesn't need to be performed again. Live plays and musicals often have long runs and each performance must go smoothly which increases the chances of something going wrong. Is it difficult to ensure plays and musicals run smoothly and do live performances have very long rehearsals before performances. Do producers use special methods to ensure performances go without a hitch eg ensure actors remember their lines.