To get a tourist visa you can now apply online for an e-visa. For other types of visa, you need to apply at a Thai Embassy outside of Thailand. Check the requirements in details before you apply and if you can, use an agency to help with the whole process.