I've seen a lot of really good people get
very badly hurt pursuing a Ph.D. I did
get a STEM field Ph.D. but didn't get
hurt.

For a good and broad view of the problem,
buried in D. Knuth's The TeXBook is

"The traditional way is to put off all
creative aspects until the last part of
graduate school. For seventeen or more
years, a student is taught examsmanship,
then suddenly after passing enough exams
in graduate school he's told to do
something original."

Yes, here Knuth identifies a significant
challenge.

Compared with the OP, here's a very
different and much more specific approach
that clearly makes a lot of sense and that
worked well for me:

First, note carefully that for some work
that can be called research the usual,
nearly universal criteria are that the
work be "new, correct, and significant".
Below, keep these three in mind.

Second, get a major in math, at least a
good undergraduate major in pure and
applied math and hopefully enough more in
pure and applied math for roughly a
Master's in math. Even if you don't care
about the Master's degree, I do very much
recommend getting the math for a Master's
degree.

Why pure math? The pure math gives you
the crucial, central, foundational tools
of math, that is, many crucial
prerequisites and, broadly, the ability to
state and prove theorems. E.g., you will
learn how to write math, and that alone
will start to put you ahead, even of some
high end professors.

What pure math? For your research likely
mostly you will use the part of math
called analysis but in your studies for
more you will also want at least the
basics of abstract algebra and maybe
differential geometry, combinatorics, and
maybe even some in foundations. In
addition, if you have some reason to
believe you can get some value from
algebraic topology or geometry, then, sure
study those.

Why applied math? Likely applied math
will be closer to the math you will use
for your research. What applied math?
Sure, e.g., statistics, numerical linear
algebra, ordinary differential equations,
more in numerical techniques,
optimization, stochastic processes, etc.

Third, get your Ph.D. in some field of
engineering -- computer science,
electronic engineering, mechanical
engineering, civil engineering, operations
research, statistics, etc.

Three biggie points:

(1) In science and engineering, by far the
most highly respected research is that
which mathematizes the field. Good work
here can help meet the criterion of
"significant".

(2) Work in math, well supported with
theorems and proofs, is much more
difficult to criticize than work that is
mostly just experimental or empirical.
Good work here can be help meet the
criterion of "correct".

(3) The standard and severe weakness of
the backgrounds of researchers in most of
science and in engineering is way too
little in math. Thus, there are a lot of
good research problems they can't address.
So, your good work here can be help meet
the criterion of "new".

So, with your background in math, on
(1)-(3) you will have at least a good --
maybe even an overwhelmingly strong --
comparative, competitive advantage.

Another point if you care: Unless your
family wants to donate $10+ million or so,
it is just super tough to get into an Ivy
League university. But getting in as a
grad student is much easier -- e.g., I got
accepted to Cornell, Brown, and Princeton.

So, you should intend that your research
be essentially math for that field of
engineering. Usually you will aim to use
your math tools to solve a relatively
practical problem in that field of
engineering, but you might use your math
to add to the basic theory of that
field; for some wild guesses, you might do
something in the theory of predators and
prey in environmental engineering; maybe
you would have been the one who did Kalman
filtering in electronic engineering; maybe
in mechanical engineering and continuum
mechanics you will make some nice
theoretical contribution to materials
science.

Why engineering instead of pure math or
physical science? (1) Engineering has no
end of practical problems -- say, from
outside of, and neglected by, academics --
to be solved. So, if you pick, attack,
and solve a problem important in practice,
then there is a good chance your work will
meet the criterion of "new", since the
work is mathematical, "correct", and since
the problem was important in practice,
"significant". (2) In pure math and
physical science, the range of candidate
problems is much more narrow, e.g., in
physics you can try to say what dark
energy is -- lots of luck doing that.

So, right, for a research problem in some
field of engineering, maybe pick a
practical problem that is considered
important and that you found someplace,
maybe outside academics, maybe on a job,
maybe a real job or maybe just a summer
job or an internship. I did that: I
picked a problem I found at FedEx.

Then, it will be quite good for you to
have the problem in mind when go for your
Ph.D. I had the problem and a good,
first-cut, intuitive solution (worked out
on an airplane flight) before I entered my
Ph.D. program. In my first year, I took
some advanced, relatively pure, not often
taught, graduate math coursework that gave
me good math prerequisites to let me
convert my intuitive solution a solid math
solution. So, in my first summer, in six
weeks, independently, alone in the
library, I worked out the math, with
theorems and proofs, and walked out with a
50 page manuscript that was the original
research for my Ph.D. dissertation. I
recommend doing such a thing.

Getting into research early is commonly
considered good advice: E.g., IIRC, the
Princeton math department has said on
their Web site that a student should have
some research underway in their first
year. Even, better, have the core
research done before the second year --
which is what I did and, I believe, a
strong advantage in getting the Ph.D.

The math gave me another advantage: In a
course, a problem was apparent -- a
tricky, deep question about the
Kuhn-Tucker conditions. There was no
answer in the course, and I could find no
answer in the library. So, I attacked the
problem -- the key was some pure math I
had -- and found a surprisingly nice
solution, in two weeks. I wrote up my
solution and got credit for a reading
course. But the work was publishable --
presto, bingo, at that university the
criteria for a Ph.D. dissertation was that
the work be "an original contribution to
knowledge worthy of publication". Well,
the best way to show that some work is
"worthy of publication" is to submit it
for publication and have it accepted. I
did that. So, technically that work was
enough for my Ph.D. dissertation, a second
one.

For that problem in the Kuhn-Tucker
conditions and for my dissertation
research, I never had any real faculty
direction. I recommend: Don't wait for
the faculty to provide a good problem or
direction. Instead, on your own as much
as you can, at least if it is easy for
you, and it was for me, pick a good
problem, do the research, get the work
ready for publication, and, hopefully,
publish it. For a graduate student to
have, early on, from largely independent
effort, some work worthy of publication
makes essentially everything else in the
Ph.D. program and the start of a career
much easier and better.

Okay, how to do the research? Well, for
me, the core, hard work of the research
was a little more involved but, really,
not much more difficult than the more
difficult exercises in standard, advanced
pure math texts.

The difference was, for research, in part
need to keep in mind some view from higher
up, say, 50,000 feet down to 1000 feet and
don't always be crawling around on the
ground with the lowest level details
(which is common and usually effective
enough in solving exercises).

Next, guess: To find and prove a new
result, first have to guess it. Sure,
make educated guesses based on your
solid background but also work just
intuitively. So build intuitive models
and, as you learn more, revise the models
to make them more accurate.

E.g., during the work, is A true? Well,
it doesn't seem wrong right away
intuitively. But, if A is true, then,
hmm, B is true. Could B be true? At
least, first-cut, intuitively, naw, not a
chance (this may be wrong, but let that
happen for now). So, likely A is not
true.

You can do a lot of this in your head
without writing anything. And, even if
slowly, you will learn to do at least some
derivations in your head.

Now, for C, intuitively it looks true.
So, try to prove C. Gee, the proof
doesn't work. Then observe: The proof
doesn't make good use of all the
hypotheses of C; so, you've been trying
to prove something more general than C
and likely not true. Bummer. So look
again at the hypotheses of C and try to
see how they are essential and how to
exploit them.

So, continue in this way, maintaining a
good view from above the ground level,
with lots of intuition and guessing and
trying to prove some little things.

When you get a proof of a result that
looks good, then write it up, carefully,
cleanly, put a date and title on the first
page, put a staple in the UL corner of the
sheets, and toss it on a stack, continue
on, maybe building on what you have.

There is also Polya, How to Solve It.

From A. Wiles, the guy who solved Fermat's
last theorem and just won the Abel Prize,
is

"Perhaps I could best describe my
experience of doing mathematics in terms
of entering a dark mansion. You go into
the first room and it's dark, completely
dark. You stumble around, bumping into
the furniture. Gradually, you learn where
each piece of furniture is. And finally,
after six months or so, you find the light
switch and turn it on. Suddenly it's all
illuminated and you can see exactly where
you were. Then you go into the next dark
room ..."