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."
This is 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).
Buck ["Selected Indo-European Synonyms"] notes that "Words for 'poison', apart from an inherited group, are in some cases the same as those for 'drug' ...." In addition to the Greek word he has Latin venenum "poison," earlier "drug, medical potion" (source of Spanish veneno, French venin, English venom), and Old English lybb.
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.