How to ask for a letter of rec from a first semester professor in a masters' program?
After you complete the course and receive an A, you email your professor along the following lines. 


  "Dear Prof X, I was a student in your class Z. I found it very
  interesting and really enjoyed learning about the subject (don't say
  this if you didn't). Next year, I am thinking about applying for W.
  Would you see yourself in a position to write a letter of
  recommendation for me for those applications? If you want, I'm happy
  to discuss my plans in person. Sincerely, Q"


Note that letter of recommendation that simply state "Student Q took my class Z, and they got an A" will not be particularly valuable for PhD applications. I would make sure to interact with the professor beyond just passively taking the class and really stand out. Don't do this just for the sake of getting a LOR (they can tell). Only if you're actually interested in the material!

Also, use those interactions to discuss your academic career plans with the professor! Maybe they know someone in your specific field of interest, maybe they are looking for PhD students themselves etc. That could become more useful than the LOR!