You're not considering that food has a limited shelf life, seasonal, difficult to distribute efficiently and the customers have highly variable purchasing powers. Also local production is incredibly sensitive to local environmental variation. We already produce enough food to feed nearly twice the global population, and yet plenty of people are malnourished.
I would personally suggest that the best way to prevent famines is to improve food storage and distribution methods, and have robust systems for environmental or conflict induced local famines. Though the unbalanced nature of consumer wealth is also important - it makes sense to waste 50% of your crop selling it in Europe if you can sell it for 3x as much than locally. So maybe the best thing is simply to raise the wealth of poorest people in the world?