You can apply after your education provider has told the Home Office that you've successfully completed the course. You must apply before your Student visa expires.