Does the longest road need to have settlements/cities at endpoints?
It is 8, the relevant rules are exactly what you quoted.


  The Longest Road is a continuous road connecting two intersections, which consists of at least 5 individual road pieces and is not interrupted by game pieces belonging to other players. It has more individual road pieces than any other connecting road of this type.


The bolded part tells you what "connecting road" refers to, in this case 2 intersections. It doesn't matter if they have settlements/cities or not.