Just to keep things straight, geologists use the word “magma” for molten rock that is still underground, and the word “lava” for rock that has made it to the surface.
So, you want to know how magma is made? There is a lot of heat within the earth, and this heat is produced by radioactive decay of naturally-ocurring radioactive elements within the earth. It is the same process that allows a nuclear reactor to generate heat, but in the earth, the radioactive material is much less concentrated. However, because the earth is so much bigger than a nuclear power plant it can produce a lot of heat.
Anyway, this heat is enough to partially melt rocks in the upper mantle, about 50-100 km below the surface. I say partially melt because the rocks don’t completely melt. As you can guess, most rocks are made up of more than one mineral, and these different minerals have different melting temperatures. This means that when the rock starts to melt, some of the minerals get melted to a much greater degree than others. The main reason this is important is that the liquid (magma) that is generated is not just the molten equivalent of the starting rock, but instead something different.
You could think of making a “rock” out of sugar, butter, and shave ice. Pretend that they are mixed equally so that your rock is 1/3 sugar, 1/3 butter, and 1/3 shave ice. If you start melting this “rock”, however, the “magma” that is generated will be highly concentrated in the things that melt more easily, namely the ice (now water) and butter. There will be a little bit of sugar in your magma, but not much.
Anyway, the most common type of magma produced is basalt (the stuff that is erupted at mid-ocean ridges to make up the ocean floors, as well as the stuff that is erupted here in Hawai’i). Soon after they’re formed, little drops of basaltic magma start to work their way upward (their density is slightly less than that of the solid rock), and pretty soon they coalesce with other drops and eventually there is a good flow of basaltic magma towards the surface. If it makes it to the surface it will erupt as basaltic lava.