Well that is an interesting question. First of all, there is no one answer to this question. The best answer may even be that you cannot, you just need to do it. However, since I was asked I will try to answer the questions anyway. So here you go. I like lists so I will put my response in a list. It is not extensive so I also welcome additions in the comments.
Think about why you want to get your PhD. This journey is more than just a notion. It can be very difficult and long so it needs to be something you are passionate about. I was once told that you need to really love your research topic in the beginning because by the end you may hate it. If you start off with a lukewarm feeling, it will be a torturous process for you.
Research the university, lab, and principal investigator extensively. Ask to speak to the postdoc, graduate and undergraduate students in the lab. Many people end up with professors or in programs that make their life miserable. If you can, do a campus visit and closely evaluate what they say and do as well as the non-verbal cues.
Start curating relationships with your recommenders now. Professors are very busy and notorious for missing deadlines. Give them your materials and a schedule of when recommendations are due at least a month in advance. I like a spreadsheet with email addresses, mailing addresses, hyperlinks, programs applying to, etc. Also provide them with a copy of your statement of purpose, resume, transcript and any personal details that help them write the letter. Also be respectful of their time, do not ask for more than 5 recommendation letters. Make sure to include a dream school, a safe school and something in between. Be realistic about your GPA and test scores as you consider universities to apply to.
In general, graduate assistantships do not pay well. Start planning at least a year before you plan to start your program to research and identify other sources of funding. Fellowships, grants, scholarships, etc. I did extra work that was closely related to my research or future job aspirations so it did not feel like work. I taught HS math, tutored for the athletic department and worked for a tutoring company.
Keep all of your notebooks and textbooks from undergraduate degree program. They were invaluable in helping me prepare for my preliminary, qualifying or comprehensive exams. Using those books to study all summer in a dorm in Japan was crucial to getting me to pass my qualifiers in 1999. Before selecting a program, use those materials to reflect on what topics were the most interesting or exciting to you. This will help determine what you want to study in graduate school.
This is one piece of advice that I received that I wish I had followed. Once you are in graduate school, try to make every class project relate to your thesis or dissertation topic. For example, use the project for your literature review, prototype or beta testing, etc.
Build a support network of champions and cheerleaders within and outside your university and discipline. Even if they don't totally understand what you are doing, they help keep you going when you get frustrated, down and want to quit. Mine was some of my friends from undergrad as well as lab mates.
Finally, be forgiving of yourself and realize that this is a marathon, not a sprint. It took six years after my masters to earn my PhD. I went through a couple of topics and eventually added on an additional advisor in my third year. The good news is I now had a topic but the bad news was that I had to manage two different people. Since my work was multidisciplinary, I had an EE advisor and CS advisor. This was because my research topic was controls and human-robot interaction. They did not always agree on the direction of my work and I had to learn to balance requests to please them both.
Remember, once you are done, people will call you doctor and they will not usually ask how long it took. Your goal is to get to that finish line without being damaged, bruised, crazy, bitter, and unhealthy.