Can anyone write a paper and then publish it in a journal? I know nothing about the bureaucracy of the academic world when writing papers but I sometimes need or enjoy to read academic papers.

Usually all the papers I've read were written either by professors or by reasearchers (I'm guessing PhDs). Some papers were written by people working at Google and they were PhDs too. 

My question is: can anyone write a paper or is some minimum level of education (say a PhD for instance) required? Of course I'm not asking if a persone can wake up tomorrow and write a paper on quantum physics without knowing anything at all of physics.

EDIT: when I said "write", what I meant was having the paper published. Sorry!
In principle: Yes, of course!

No journal I know has a rule that requires a minimum level of education or a specific affiliation. But in order to be accepted for a journal with reasonable reputation, there are several requirements:


Contribution: With more education (not necessarily a higher degree) it gets easier to provide a better contribution. As you said, just waking up with a great idea without even knowing the fundamentals of the field of research before is unlikely.
Novelty: For an external person it is hard to decide if he has really found something new or he was just reinventing the wheel. That is much easier if you are part of the research community. That does not necessarily require any affiliation, but for example the regular participation at conferences and workshops.
Experience: You need experience in many areas to write a good paper. A lot of (if not most) papers are rejected not because of bad ideas, but because of wrong experimental setups, wrong application of statistical methods, ugly looking plots that do not provide confidence intervals ... and most importantly because the paper was not written in a convincing way. You can not learn these things by just reading a book at home.
Time: Research requires a lot of time! If the university pays at least part of your bills you have more time to do research.
Money: Depending on the journal, publishing might be very expensive. With an affiliation at a university it is easier to find someone who pays for your publication.
Reputation: Last but not least, there are things, such as reputation of the author, that should not influence a reviewers decision, but they do at least sometimes.