It occurred on January 27, 1967, during a launch pad test at Cape Kennedy, Florida.
While it was a test flight, it was not a typical test flight, but one where the crew was actually inside the spacecraft, simulating a launch. The fire was caused by an electrical short circuit and the crew, Gus Grissom, Ed White, and Roger Chaffee, tragically died in the fire.
It's important to note that Apollo 1 was never meant to go to the moon, but was designed to test the crew's ability to function in a lunar module.