Yes, you need a visa when you plan to leave the Turkish airport.

Apply for your visa here:  https://turkishvisa.com/


NOTE - If you will NOT leave the transit lounge at the airport you are not required to have a visa.  

Otherwise, if you wish to enter any Turkish city then, YES you will have to apply for a tourist visa online.