Good question! It has taken a lot of scientific brain power to answer the question of 'how does magma form'. The manner in which we use the terms magma and lava can be confusing; molten rock is referred to as magma when in the Earth's crust or mantle; and as lava when exposed on the Earth's surface.
The melting temperature of rocks in the upper part of Earth's mantle, where most magma forms, is in the neighborhood of 1,100 Celsius. So you either have to bring the temperature in the upper mantle to that level; or, you reduce the pressure - which promotes melting; or, you add water which acts as a flux to lower the melting temperature of the rock.
The lower crust and mantle include radiogenic elements such as potassium, uranium, thorium. Radiogenic decay of these elements releases heat. When added to the primordial heat of Earth's formation, the temperature is sufficient to melt small quantities of upper mantle rock.
Adding water to the mix, which occurs along zones of subduction - where oceanic crust sinks back into the mantle - increases the likelihood of melting. Water acts as a flux, lowering the melting temperature of the rock. The volcanic chain referred to as the 'Ring of Fire' forms adjacent to subduction zones as a result of water released from the sinking oceanic crust being introduced into the mantle and inducing melting. Molten rock, i.e., magma, is less dense and more buoyant than the surrounding rock, as a result magma rises through Earth's crust. Most magma is trapped in the crust, but some erupts onto the Earth's surface as lava.
There, I've synthesized 100 years+ of geologic studies of magma formation into 4 short paragraphs. The attached image shows the likely zones of melting of mantle rock.
I hope this helps. MC