The code of Hammurabi included laws regulating beer and beer parlours and it dates back to about 1754 BC, indicating that beer parlours and the commerce of beer were already common at that point. Taverns were also common in the Roman Empire.
However with the fall of the Western Roman Empire they seem to have somewhat faded into the background. Wine was too expensive for the lower classes, and with the lack of trade was unavailable in areas that couldn't grow grapes.
During the early Middle Ages, beer (cheap, available ingredients) brewing was mostly a domestic activity and produced for the family.
During the 13th-15th centuries it became a commercial activity, monasteries and pubs were brewing and selling in large quantities. This was made possible by the use of hops, which not only improved the taste but also acted as a natural preservative (long term storage/transport).