This mostly happens at the same location that earthquakes occur, plate boundaries.
Magma can percolate upward towards the surface, stalling and accumulating at various depths. These zones of magma accumulation are referred to as magma reservoirs and they can pressurise under certain circumstances, driving the magma to erupt at the surface.
Basic process of magma formation and movement retrieved from USGS, Public Domain
The locations where magma erupts are called volcanoes. Volcanoes come in a wide variety of shapes and sizes.
Perhaps the most well-known type of volcano is the stratovolcano due to their recognisable conical shape. An example is Mount Vesuvius that is near Naples, Italy.
Mount Vesuvius, 79 AD
Mount Vesuvius is most famous for a violent eruption occurring in 79 AD. This eruption destroyed the Roman cities of Pompeii and Herculaneum, killing thousands of civilians.
It was described by Pliny the Younger in two letters addressed to the Roman historian Tacitus. These letters gave a remarkably accurate description of this type of eruption, which was subsequently named a Plinian eruption by modern day geologists.
A Plinian eruption releases a high-temperature mixture of gases and fragments of broken magma into the atmosphere for a period ranging from hours to days.
This mixture forms a dark-grey vertical column that rises much like a hot air balloon reaching altitudes of several tens of kilometers. The base of this vertical column can become unstable and collapse under its own weight.
This is what happened in 79 AD when Mount Vesuvius erupted. A mixture of hot gas and magma fragments hurled down the flanks of the mountain at speeds of hundreds of kilometres an hour. These features are called pyroclastic density currents and destroy everything in their path.
Some of the pyroclastic density currents produced by the 79 AD eruption made their way to the towns of Pompeii and Herculaneum.
These events have preserved an exceptional archaeological record of Roman life and are visited by millions of tourists every year.