There are several ways in which a volcano can form , just as there are several different kinds of volcanoes.
Volcanism is part of the process by which a planet cools off.
Hot magma, rising from lower reaches of the Earth, eventually, but not always, erupts onto the surface. During the eruption lava and ash form a cone. This cone is what we know as a volcano. Strong earthquakes accompany rising magma just before an eruption, as illustrated in this picture. Those are composite volcanoes which form as a result of subduction of the nearby lithosphere.