The optical path between any two points is proportional to the time of travel.
The distance traversed by light in a medium of refractive index $\mu$ in time t is given by
$d = vt ... (i)$
where v is velocity of light in the medium. The distance traversed by light in a vacuum in this time, $\Delta = ct$
$ = c.\frac{d}{v} [from E (i)]$
$ = d \frac{c}{v} = \mu d ... (ii)$
$ \big(Since, \mu = \frac{c}{v}\big)$
This distance is the equivalent distance in vacuum and is called optical path.
Here, optical path for first ray =$n_1 L_1$
Optical path for second ray = $n_2 L_2$
Path difference = $n_1 L_1 - n_2 L_2$
Now, phase difference
$ =\frac{2 \pi}{\lambda} \times $ path difference
$=\frac{2 \pi}{\lambda} \times (n_1 L_1 - n_2 L_2) $