I photographed this oil refinery in New Mexico. How do they make gasoline from crude oil?
Crude oil is actually a mixture of many different hydrocarbon chemicals. Refineries use fractional distillation to separate those chemicals. The crude oil is slowly heated under controlled conditions. Different chemicals in the mixture vaporize at different temperatures, so by collecting the vapors at specific temperatures, you can condense the vapor into either gasoline, kerosene, diesel oil, etc.
Gasoline is also produced by a process known as cracking. Heat (thermal cracking) and chemical reactions (catalytic cracking) are used to break larger, less useful hydrocarbon molecules into smaller molecules of gasoline, kerosene, etc.