You apply for a visa at the German embassy in your country. Make sure that you apply for the visa that corresponds to the actual purpose of your stay. This is the only way to ensure trouble-free extension or conversion of your visa by the foreign nationals' registration authority of your place of residence in Germany. For example, it is impossible to stay permanently on a visa that was issued only for a temporary stay.
The best thing to do is to inquire in plenty of time to the German embassy in your country about which documents you need for your application.
Federal Office for Migration and Refugees (BAMF)
Important information about residence and settlement permits in Germany (German, English, Turkish)
Federal Foreign Office
Information about the Immigration Act (German, English)