I know a lot of questions are asked about letters of recommendation, but I was unable to find anything on this site or the internet in general that spoke to the particular issue of how to build the sort of relationship with a professor that results in good letters of recommendation. I get that you should of course do pretty well in the class and participate and go to office hours and be generally easy to work with and stuff (and ideally do research with the professor), but apart from that, is there nothing more you can do?
I know some might be eager to answer that you shouldn't be so mercenary about it (i.e. you should just organically be interested in the material and the professor and the good letter of recommendation will follow), so allow me to provide an example where this did not work out. I got a letter of recommendation from my favorite professor in college, which for some reason I was able to see (it was about a decade ago, so I forget how; I had waived my right to see it). Even though I thought he liked me (I went to office hours multiple times; I had two classes with him, both of which I did well in; he encouraged me to go for a fellowship; he even went out of his way to see a play I was in), the letter was the most basic "this student was in my class" sort of letter you could possibly imagine. It was such an incredible slap in the face.
Maybe he was just a jerk and that's that. Maybe I should have asked for a "strong" letter of recommendation (which I didn't know at the time was what you were supposed to ask). But regardless, given the vagaries of human relationships on top of the limitations of your own abilities, how is it even possible to get a strong letter of recommendation?