Phd while on h1b

Hello team,
I am considering pursuing Phd while on h1b. Is it legal or do we need to convert to F1 ?