Ol' Isaac Newton goofed. He wrote:
$F = \frac {G M_1 M_2}{d^2}$
when he should have written:
$F = \frac {G E_1 E_2}{d^2}$
(with a different value and units for G) where it is to be understood that $E$ is the total energy of something.
For light, $E=hf$. Any electromagnetic wave has energy and momentum. For a simple plane wave, this is it. (We'll ignore momentum for now.)
For a bowling ball or planet, $E=\frac {c^2 m} {\sqrt{1-(v/c)^2}}$.
I like to put the $c$ before the $m$ because it's just a coefficient, a constant, and that it the convention throughout most of physics. Everyone is brainwashed to write $mc^2$ but let me get off that soapbox and instead preach about this basic formula for energy of a moving massive particle (meaning things as big as stars, galaxies, etc).
If the particle isn't moving, it gets simpler: $E = c^2 m$. For the situations Newton was pondering, planets and apples, $v \ll c$, and we can have a pretty good approximation by just setting $v=0$.
This way I rewrite Newton's law of gravity resembles Einstein's equation for general relativity.
We're only half done. There's also $F=ma$. Again, Newton goofed. He should have written $F = \frac{dp}{dt} $ where $p$ is momentum. Again, light has momentum, and so do bowling balls and planets. Photons being massless, you can't use the old formula $p=mv$ but waves do have momentum, $p= \frac{hf}{c}$, and this can change with time due to "force". The old formula is fine for bowling balls, planets and expensive vases.
The truly modern way to describe gravity and the motions of things flying around, massive or massless, it to describe curved space-time and the geodesics that follow the curvature, which are the paths of things that aren't being acted on by any forces other than gravity. But this is a different viewpoint, kind of like the difference between saying Earth has gravity which caused expensive vases to fall and break, versus being an astronaut in orbit enjoying "zero gee".
All questions about light, or photons, not fitting the familiar classical formulas as taught in high school level physics, is due to not using the more general formulas we've learned from relativity and quantum mechanics.
Modern theoretical physics is all done with Lagrangians and Hamiltonians. There are ways to write these, which are formulas dealing with energy, for waves and hard objects, massless or massive, in all kinds of plain or exotic situations.
From the Lagrangian or Hamiltonian we can derive the familiar relativistic formulas for massive or massless quanta, or the simpler classical formulas for massive objects. The trouble comes from confusing these different approximations.
Silly of Newton to not know about 20th Century relativity!