The three ways that magma can be formed are through heat transfer, decompression melting and flux melting. The process of magma creation is referred to by geologists as magmagenesis and occurs at the upper mantle of the Earth's crust due to plate tectonic effects.
Heat transfer is the process through which a rising column of magma sends heat to the rock around it, pushing it beyond melting point and creating rhyolitic magma. Decompression melting, on the other hand, occurs when two separate tectonic plates separate, causing the mantle below it to rise between them. Once pressure drops, the raised-up mantle begins to melt into magma.
Flux melting occurs when volatile matter, such as sulfur gases and water, is stirred into the body of the rock. This process typically precludes the creation of volcanic arcs and magma.