Porter was promoted to second lieutenant on June 18, 1846 and First Lieutenant on May 29, 1847. He served in the Mexican–American War and was appointed a brevet captain on September 8, 1847, for bravery at the Battle of Molino del Rey. He was wounded at Chapultepec on September 13, for which he also received a brevet promotion to major. He was an original member of the Aztec Club of 1847, a military society composed of officers who served during the Mexican War.