It is clear that q must be odd, hence q≥3.
Case 1. If p=2, then we get 2q+1=q2+7. For any n≥4 we have 2n+1>n2+7 (by induction). Hence q=3, and we get solution (2,3).
Case 2. If p≥3, then we can write, and using Fermat Little Theorem,
qp=2pq−7=2(pq−p)+(2p−7)⇒q∣2p−7
and
2pq=qp+7=(qp−q)+(q+7)⇒p∣q+7.
Set q+7=kp.
If 2p−7≤0⇒p=3, hence q∣−1, not possible.
If 2p−7>0⇒2p−7≥q, hence 2p≥q+7=kp, and we get k≤2. Therefore, we have only two possibilities for k: k=1, k=2.
If k=1⇒q+7=p⇒q∣2q+7⇒q=7 and p=14, not a prime, contradiction.
If k=2⇒q+7=2p. If q>p, then we have p,q≥3. Hence 7=2pq−qp=pq≥27, since pq>qp, not possible. Then p>q, and we get q+7=2p>2q⇒q<7⇒q=3 or q=5. In first case we obtain p=5 and in the second case contradiction. Finally, the solutions are (p,q)=(2,3),(5,3).