On July 2, 1812, Porter hoisted the banner "Free trade and sailors' rights" as captain of USS Essex.
[2] During the First Barbary War (1801–07), Porter was first lieutenant of Enterprise, New York, and Philadelphia and was taken prisoner when the latter ran aground in Tripoli harbor on October 31, 1803.
Porter purchased the grand home built by the judge and politician David Lloyd in Chester, Pennsylvania.
In 1809 he moved with Porter to Washington, where he met Secretary of the Navy Paul Hamilton and expressed his wish for a midshipman's appointment.
Assigned to Constellation under the command of John Rodgers, he saw action in the battle against L'Insurgente, notably saving the mast by cutting away slings after it was damaged.
[citation needed] In February 1813 he sailed Essex around Cape Horn and cruised the Pacific, attacking British whalers.
Porter's first action in the Pacific was the capture of the Peruvian merchantman Nereyda, releasing the captive American whalers on board.
Porter's usual tactic was to raise British colors to allay the whaler's suspicions, then once invited on board, he would reveal his true allegiance and purpose.
[citation needed] From 1815 to 1822, he was a member of the Board of Navy Commissioners but gave up this post to command the expedition for suppressing piracy in the West Indies (1823–25).
While in the West Indies suppressing piracy, Porter invaded the town of Fajardo, Puerto Rico (a Spanish colony) to avenge the jailing of an officer from his fleet.