late 14c., farmacie, "a medicine that rids the body of an excess of humors (except blood);" also "treatment with medicine; theory of treatment with medicine," from Old French farmacie "a purgative" (13c.) and directly from Medieval Latin pharmacia, from Greek pharmakeia "a healing or harmful medicine, a healing or poisonous herb; a drug, poisonous potion; magic (potion), dye, raw material for physical or chemical processing," from pharmakeus (fem. pharmakis) "a preparer of drugs, a poisoner, a sorcerer" from pharmakon "a drug, a poison, philter, charm, spell, enchantment." Beekes writes that the original meaning cannot be clearly established, and "The word is clearly Pre-Greek." The ph- was restored 16c. in French, 17c. in English (see ph).
Meaning "the use or administration of drugs" is from c. 1400; the sense of "art or practice of preparing, preserving, and compounding medicines and dispensing them according to prescriptions" is from 1650s; that of "place where drugs are prepared and dispensed" is recorded by 1833.