Disclaimer: from now on, the feminine form will designate both genders when it is necessary not to discriminate for a gender when writing in the third person.
Every PhD program will ask you for three (or less commonly, two) letters of recommendation. These weigh heavily to the eyes of the committee responsible for the admissions process so choose who will write them wisely. Whenever the option is given, please waive the right to see the letters; if you do not, it will be taken less seriously. And, unlike MBA admissions, where it is quite common for recommenders to ask you to write a letter of recommendation so that they can transcribe and sign it afterward (a few will do the appropriate modifications in due course, e.g. if the recs are to be sent on official business letterhead), here it is not recommended to write the letter yourself so that the referee can transcribe and sign.
Some people might say that the referees are mostly “go big or go home” in that respect and, therefore, letters of recommendation do not mean as much as they used to. However, even if you chose someone who knew you well, and not simply because you earned a high grade in their course (especially if it’s a challenging course), or collaborated in research with you for a short period of time, if they can only write a neutral letter at best, you’d be better off asking another person that knew you well in some capacity (preferably in a research capacity).
If you did enough work with someone to earn a co-authorship with her, then by all means ask that person first. If someone is well-known in a field, it will carry significant weight but the recommender’s fame in a field won’t necessarily outweigh a strong research-driven letter written by a lesser-known scholar if the famous referee wrote his/her letter for coursework reasons. And a research-driven letter will generally be stronger if you published with a given referee than if you didn’t publish. So make sure the referees will be specific enough in their reasons for recommending you because your recs will be a lot better that way. Because, alas, some professors will be rather generic in their writing and write nearly identical comments for every student they vouch for.
If you exhaust your research-driven letters before you go to the count of three, don’t fret! But you still have to choose a referee according to how advanced the course you took with her was, as well as the grade in that aforementionned course. Among coursework-driven letters, the better letters will usually come from a professor that taught you an advanced course in which you earned a high grade.