Summarize this article:

To do so, hold down the Power button on the side of your phone's casing and then swipe the slide to power off switch at the top of the screen right. If you're using an iPhone 5 or older, the Power button is on top of the phone. Once dust or grit builds up in your headphone jack, it can cause a whole host of problems such as getting your iPhone's audio stuck on headphones mode or making your headphones malfunction; you can use a Q-tip to remove the aforementioned build-up. If you're using an iPhone 7, you'll need to cut the top three quarters or so off of the Q-tip so that it can fit into the lightning port at the bottom of your phone. Do so gently, without forcing the Q-tip. Doing so should remove some of the dust or dirt from your headphone jack. You may have to repeat this process several times before your iPhone's headphone jack is clean.

Summary:
Turn off your iPhone. Acquire a Q-tip. Insert the Q-tip into the headphone jack. Twirl the Q-tip, then remove it.