Magma forms from partial melting of mantle rocks. As the rocks move upward (or have water added to them), they start to melt a little bit. These little blebs of melt migrate upward and coalesce into larger volumes that continue to move upward. They may collect in a magma chamber or they may just come straight up. As they rise, gas molecules in the magma come out of solution and form bubbles and as the bubbles rise they expand. Eventually the pressure from these bubbles is stronger than the surrounding solid rock and this surrounding rock fractures, allowing the magma to get to the surface.
Regards