How come phonetically is spelled with a ph?

When the letters 'p' and 'h' are together in a word they make the same sound as 'f'. Therefore, "phonetically" can be spelled with 'ph' even though it makes an 'f' sound.