Some ancient bacteria with very fluid membranes engulfed others and maintained a symbiotic relationship with them
Some of the engulfed bacteria could oxidise glucose releasing ATP - these evolved into mitochondria
Some of the engulfed bacteria could use carbondioxide and water to synthesise glucose and oxygen using energy from light - these evolved into chloroplasts