SACRAMENTO, Calif./LOS ANGELES (Reuters) - California Governor Jerry Brown on Friday signed into law the state's first comprehensive regulations of medical marijuana, two decades after legalization fueled a wild west of disparate local rules, a gray market in cultivation and concerns about the ease of obtaining the drug.

The package of three laws, viewed by some as a possible framework for the eventual legalization of recreational marijuana in the most populous U.S. state, would establish a Bureau of Medical Marijuana Regulation and oversee such activities as cultivation and dispensary licensing.

The bills, which take effect in 2018, "establish a long-overdue comprehensive regulatory framework for the production, transportation and sale of medical marijuana," Brown, a Democrat, said in a signing statement on Friday.

The legislation regulates the cultivation of marijuana, which now frequently takes place on hidden gray market farms that strip water from the state's forests. The laws also require state tax and agriculture officials to develop a way to track the sale and development of marijuana products, which remain illegal under federal law.

For years, the U.S. government's pot ban made California lawmakers reluctant to bring themselves into the conflict between federal and state law by creating rules for medical cannabis, said Assemblyman Jim Wood, a Democrat who authored one of the bills signed by Brown.

Then in the last three years, voters in Colorado, Washington state, Alaska and Oregon legalized the drug for recreational use.

"It was the votes for legalization that kind of opened the gates so to speak to have some more significant discussions around the issue," Wood said.

The package of laws was welcomed by medical marijuana advocates, who said some cities had cracked down too hard on local dispensaries in the absence of strong state regulations.

Organizations favoring legalization of recreational marijuana for adults are re-working proposed California ballot initiatives to accommodate the new laws, said Lauren Vazquez, a spokeswoman for the Marijuana Policy Project which works to legalize the drug.

But opponents said the laws would codify a business they still see as promoting potentially dangerous drug use.

"People do not want marijuana stores in their communities," said Kevin Sabet, co-founder of the group Smart Approaches to Marijuana, which opposes legalizing recreational cannabis.

Sabet is skeptical of the state's current free-for-all medical marijuana environment, in which it is easy to get a doctor's recommendation and medical pot is often smoked, the method preferred by recreational users.

(Writing by Sharon Bernstein; Editing by Lisa Lambert)