The Pirates bounced back from a Tuesday setback to win for the 10th time in 11 games.
Alvarez hit his home run in the fifth inning to break a 1-1 tie and lift Locke to his eighth straight victory.
Locke (8-1) gave up three runs on seven hits over 5 2/3 innings.
Domonic Brown hit a two-run homer and Delmon Young had his 1,000th hit for the Phillies, but Philadelphia lost for the third time in four games.
John Lannan (1-3) took the loss, allowing four runs on 11 hits in five frames.
Beyonce flaunts bikini body, Blue Ivy in vacation pics
Kate Middleton recycles dress at movie premiere