First of all, it erupts because of the movements of the earth's surface. The Earth is composed of the lithosphere, mantle, and crust. The lithosphere has the several plates like a puzzle, and they move little by little. By moving, they bring about the mantle convection. For this reason, an oceanic ridge and trench that are created.
After this, magma is created by the frictional heat which is caused when the crust collides. It is a viscous liquid, like a jelly, which mixes the molten rock, gas, and other. When it is created, it gradually rises having the low density compared with other rock which has the high density within the mantle. By rising, it has lower pressure, and the amount of gas which is melted in the magma increases.