Just as an additional note to the identity provided by @Cardboard Box.
$$
\prod_{p|mn} \left(1 - \dfrac{1}{p}\right) = \frac{\prod\limits_{p|m} \left(1 - \dfrac{1}{p}\right) \prod\limits_{p|n} \left(1 - \dfrac{1}{p}\right)}{\prod\limits_{p|d} \left(1 - \dfrac{1}{p}\right)}
$$
Why does this work?
Consider the prime factorization of $m,n$, and that we are multiplying all $p$ such that $p|mn$. But, on first sight, this is the same as multiplying all $p$ such that $p|n$ together with all $p$ such that $p|m$. But what if $m$ and $n$ share a prime factor?
This means that we will multiply that prime factor (call it $p_c$) twice, although of course it can only appear once in the prime factorization of $mn$, albeit with a greater power associated.
Thus, we need to account for this shared factor, or even shared factors in case there is more than 1 shared prime factor.
To do this, divide the whole thing by prime factors of the $gcd(m,n)$. Thus, we will be "removing" the factors which we multiplied twice.
Furthermore, to go from
$$
mn \frac{\prod\limits_{p|m} \left(1 - \dfrac{1}{p}\right) \prod\limits_{p|n} \left(1 - \dfrac{1}{p}\right)}{\prod\limits_{p|d} \left(1 - \dfrac{1}{p}\right)} = \phi(m) \phi(n) \dfrac{d}{\phi(d)}
$$
consider multiplying the left side by $\dfrac{d}{d}$. Thus you can group together the $d$ with $\prod\limits_{p|d} \left(1 - \dfrac{1}{p}\right)$ in the denominator to get $\phi(d)$.
Hope this makes it easier to follow the top answer.