Why do stock prices go up

Is the increase in stock prices usually linked to company earnings or external factors?