I know people in the early 20th, 19th, and 18th centuries talked a lot about the dangers of alcoholism, but in my history classes I didn't read much about addiction to drugs like cocaine and morphine and amphetamines until the modern (ish) day, even though supposedly you could casually get things like cocaine in a pharmacy. Is it because only the very rich had access to these drugs? Or maybe there were social factors that made people less likely to become addicts?
Particularly interested in answers relating to Western Europe/the US - aware that some countries like China had major drug addiction issues.
I'm not sure what you mean by "modern." Amphetamines weren't invented until the mid-20th century. Cocaine wasn't isolated from the coca leaf until 1855. People had always chewed coca leaves, but in the raw form it's not a very strong drug, more like coffee than cocaine. Morphine wasn't isolated from opium until 1805, and wasn't marketed until 1827. Opium, however, is quite a powerful drug in its own right.
People were very worried about addiction in the 19th and early 20th centuries. That's why opiates and cocaine were eventually controlled, first under the Hague Convention of 1912, which was followed by most countries restricting at least the stronger opiates to prescription-only status during the 1920s and 30s. There were particular concerns about morphine and/or heroin addiction in the US after the civil war, and in Europe after WW1, because so many soldiers had been prescribed it for injuries and some developed addiction problems. In China during the 1830s, opium addiction was seen as such a problem that the government tried to ban opium. But since most of the opium was being imported from India by British traders, and the British traders didn't like having their market taken away, Britain sent gunboats and fought a war against China from 1839-42 to force them to rescind the ban. A second "opium war" was fought in 1853.
Prior to the 19th century, there are people writing about opium "habits" in 17th-century Britain, possibly earlier too. I'm not sure opium was particularly common in western Europe before trade with Turkey and India expanded during the early modern period. Turkish and Indian opium were the main kinds consumed (and remain the main sources of opium today for the legitimate medical trade). It doesn't seem to have been as big an issue as it became later, and was certainly outshadowed by alcoholism. I think there are a number of reasons for this. First of all was prevalence. Alcohol was just far more popular and more widely consumed, so alcoholism was a bigger issue. Second, opium use is far less disruptive than alcohol use. People who have taken opium (or heroin) are more or less able to function normally, they aren't "drunk." Above a certain level, it will interfere with performance, but by making the user fall asleep rather than go and start fights. So as a social issue it was less significant. Third, it's important to realize quite how important opium was as a medicine. As well as relieving pain, it also stops diarrhea and suppresses coughing. So it was pretty much a panacea for all of the illnesses, and one of the few medicines that was really effective. So it was seen primarily as a medicine, to which some people developed a "habit," rather than as a recreational drug.
The modern politics of drug addiction is incredibly racialized and has to be seen through the lens of racial politics. In the same period as the US banned heroin, cocaine and cannabis, it also banned alcohol, but only the alcohol ban was repealed. Why? because alcohol was the drug associated mostly with white people, and it had the backing of powerful white constituencies. The rhetoric around drugs was incredibly racist - the bans on opiates came along with the anti-Chinese immigration laws, while cannabis was presented as a Mexican drug (indeed the use of the word marijuana was promoted specifically to demonize the drug as foreign, since the word cannabis was associated with medicine), and cocaine was associated with jazz music, African-Americans and the threat they allegedly posed to white women. More recently, the ramping up of the drug war in the 1970s was totally connected with racism. There's an infamous quote from a Nixon adviser saying that their political enemies were black radicals and hippies, and they couldn't make it illegal to be black or a hippy, but if they cracked down on heroin and cannabis that would be give them an excuse to arrest black people and hippies.
In the British context, the prohibition of cannabis took place in the context of imperialism. Cannabis was associated with dissenting Muslim and Hindu groups in India (in this the British had allies among the modernizing Indian professional classes who also didn't like mystical religious practices). And also with attempts to discipline the peasantry in Egypt (again, modernizing Egyptian elites agreed with this and in fact were some of the key proponents of cannabis prohibition within the empire). It's noteworthy that heroin and cocaine prohibition weren't prioritized by Britain at that time, because unlike cannabis they weren't particularly associated with demonized racial groups, but were seen as minority interests among the white upper-middle classes. Although they were made prescription-only, they remained fairly easily available on prescription, including for addicts, until the late 1960s. At that point, Britain relented to American pressure to crack down, although the social context in Britain had also changed - mass migration from the former colonies, and the popularization of jazz music, had led to a racial politics that was more similar to the US, and heroin and cocaine had come to be associated with those often racialized counter-cultural groups.