Danny Rubin had completed and sold his script for Hear No Evil and moved from Chicago to Los Angeles to become a professional scriptwriter around 1990. His agent suggested that he prepare a "calling-card" script that he could use to gain meetings with various producers. He came up with the core idea of the script which would become Groundhog Day while at a movie with his wife Louise. He had asked himself the question "If a person could live forever, if a person was immortal, how would they change over time?" Having this character be immortal and having the world change around them would have been too cumbersome for filming. Instead he came back to a concept he had written down about two years earlier about a man living the same day over and over. With the idea of a person changing over time, this repeating day motif had found its "deeper purpose" within the new script. The two ideas, combined, answered his proverbial question as well as opened up several possibilities of drama and comedy with that framework.
Rubin first conceived of the dating aspect for the film, "being able to use your superior knowledge to pick up women", which led to the film to lean more into the comedy side. He knew he needed some calendar date to use for the day, and his earlier concept had the character reliving a late January day over and over; when he looked at his calendar, he saw Groundhog Day, February 2, as a date with great potential as a recognized holiday but that had little fanfare, which the film could be played annually similar to Christmas or Halloween specials. Groundhog Day also presented Rubin with the idea of being able to take his character out of his home town into the unfamiliar territory and relative isolation of Punxsutawney, and cementing the character being named Phil in honor of Punxsutawney Phil, as well as making him a weatherman. Rubin took about seven weeks to fix the basic concepts and "rules" for the time loop in the film, and then completed the first draft of the screenplay within three to four days.
Rubin started to shop the screenplay around to around 50 different producers. While many studios expressed interest, they told him they wouldn't be able to film it, though Rubin was able to secure additional work through these meetings. After his own agent left the industry, Rubin hired a spec agent to help sell the script more. The script got to the hands of Richard Lovett in the Creative Artists Agency, who was able to get it to Harold Ramis around 1991, leading to Ramis offering to produce the film.
Writing and casting
In the first draft of the script, Rubin had not wanted to have to explain to the audience how Phil got in the loop, and so had the movie start in medias res, with Phil already in the midst of the looping; the audience would have followed one of his days after waking up to "I Got You Babe" where he is already aware of what will be happening, and thus provoking curiosity to the audience; the film would then have used voice-over narration by Phil to provide some of the backstory. Rita also would confess to being trapped in a time loop of her own. Rubin considered this draft more in line with the black comedy Kind Hearts and Coronets, particularly on how Phil's suicides were presented.
While Ramis wanted to keep this approach, the studio put pressure to use a more standard narrative technique, forcing Rubin to rewrite the script under Ramis' direction. A major change was to restructure the film as a standard three-act piece. This second draft of the screenplay for the film established the reason for Phil to be put in a time loop, according to actor Eddie Deezen. In that version, Phil unceremoniously dumps his current girlfriend Stephanie during the introductory scenes of the film at the studio. While Phil then is at Punxsutawney, a scorned Stephanie figures a way to cast a spell to trap Phil within the loop for 10,000 years.  According to Rubin, he felt that he had taken a defensive position in writing these new scenes, feeling that it would "take away everything that was innovative and interesting and turn it into an easily-dismissed Hollywood comedy", and acknowledges that Ramis interceded on his behalf to remove these explanatory scenes while keeping the three-act format.
Another change in the second draft was to change Phil's attitude from having come to accept the nature of the time loop, to one that was more optimistic about being able to end the loop, making the role more amenable and suited for Murray's comedy talents. Ramis had known Murray since their days in The Second City improv troupe and had used in several successful films prior to Groundhog Day, so knew how to play on his strengths as to draw Murray in to take the role. Prior to Murray's casting, Tom Hanks  and Michael Keaton  turned down the lead role.
The film was shot in Woodstock, Illinois, 60 miles (97 kilometres) northwest of Chicago near the Wisconsin border, because Punxsutawney "didn’t have a town center that looked good on camera", according to Ramis, and because Punxsutawney's remote location magnified the logistical problems and expense of filming there. Woodstock was a suitable replacement for Pennsylvania in the winter months; further, Ramis knew the area as a Chicago native and recognized it would be easy to obtain licenses to film there and operation the film's production during the winter months. Punxsutawney officials, miffed that their town had been passed over, refused to allow the real Punxsutawney Phil to appear in the movie, but sent representatives to Woodstock to make sure the ceremony was being depicted accurately; according to producer Trevor Albert, the Punxsutawney officers "were actually very pleased" with their recreation of Gobbler's Knob, the site near Punxsutawney used for the Groundhog Day ceremonies. Filming began on March 16, 1992 and continued through May. Much of the filming was done in colder-than-normal weather, with Murray saying that temperatures were often under 20 °F (−7 °C), and had snowfall that lasted though May.
Punxsutawney Phil was played by a series of groundhogs collectively known as Scooter. "[The animals] hated my guts from day one," said Murray, who was bitten twice during shooting, including during the filming of the scene where he drives himself and Phil into a ravine. The bites were severe enough that he was forced to undergo precautionary rabies immunization afterward.
The Tip Top Cafe, where many indoor scenes took place, was a set created for the film; but it became an actual restaurant, the Tip Top Bistro, following the movie's success. Later, it became a coffee and Italian ice cream shop, and after that a fried chicken outlet. The Cherry Street Inn, the Queen Anne-Victorian bed & breakfast where Murray's character stayed, was a private home at the time of filming. Today, it is an actual bed & breakfast.
During the period of filming, Murray was in the midst of marital problems and several crew reported his attitude as erratic. Murray had wanted to make the film less of a comedy as to make it more contemplative, against Ramis' own direction to keep it as a comedy. Rather than to handle Murray's constant phone calls, Ramis had Murray work with Rabin in New York City directly to adjust the script to satisfy Murray's requests. Actor Stephen Tobolowsky described the script changes: "When I got the part, it was still kind of a mediocre Bill Murray movie," he said. "You know, Bill Murray, with no consequences, in comic situations ... It wasn’t until we got into the shooting that everything turned on its head. And it became not only a good movie, not only a great movie, but a classic."
During the time he was working with Rubin, Murray refused to talk to Ramis, according to Rubin. When Murray returned to Woodstock to complete filming, Ramis described his behavior as "just really irrationally mean", and difficult to work with. Following the filming, Ramis and Murray's longtime collaboration and friendship ended abruptly, without public explanation. Except for a few words at a wake, and later at a bar mitzvah, the two men did not speak for almost 20 years after the film's release. Murray finally initiated a reconciliation—at the suggestion of Brian Doyle Murray—only after Ramis entered the final stages of his terminal illness.