The earliest you should apply for your visa is 3 months before the start of your course.
But you will probably need to find and make arrangements for where you will be studying a long time beforehand.