The distance from a point not on a line to the the line is the perpendicular distance from the point to the line.
The slope of the line is (8-0)/(4-(-2)) = 4/3
An equation of the line is y-0 = 4/3(x-(-2))
y = (4/3)x + 8/3
We need to find a point, Q = (x,y), on the line so that PQ is perpendicular to the line.
So slope of PQ = -3/4
We get (y-1)/(x-5) = -3/4
y-1 = (-3/4)(x-5)
y = (-3/4)x + 19/4
But, since (x,y) is on the line, y = (4/3)x + 8/3
Therefore, (-3/4)x + 19/4 = (4/3)x + 8/3
Multiply by 12 to obtain -9x + 57 = 16x + 32
25 = 25x
x = 1 y = 4
So, Q = (1,4)
The distance from P to the line is the distance, D, from P to Q.
D = √[(4-1)2 + (1-5)2] = 5