The film was based on Murray Burnett and Joan Alison's then-unproduced play Everybody Comes to Rick's. The Warner Bros. story analyst who read the play, Stephen Karnot, called it (approvingly) "sophisticated hokum", and story editor Irene Diamond, who had discovered the unproduced play on a trip to New York in 1941, convinced producer Hal Wallis to buy the rights in January 1942 for $20,000, the most anyone in Hollywood had ever paid for an unproduced play. The project was renamed Casablanca, apparently in imitation of the 1938 hit Algiers. Although an initial filming date was selected for April 10, 1942, delays led to a start of production on May 25. Filming was completed on August 3, and the production cost $1,039,000 ($75,000 over budget), above average for the time. Unusually, the film was shot in sequence, mainly because only the first half of the script was ready when filming began.
The entire picture was shot in the studio, except for the sequence showing Major Strasser's arrival, which was filmed at Van Nuys Airport, and a few short clips of stock footage views of Paris. The street used for the exterior shots had recently been built for another film, The Desert Song, and redressed for the Paris flashbacks. It remained on the Warners backlot until the 1960s. The set for Rick's was built in three unconnected parts, so the internal layout of the building is indeterminate. In a number of scenes, the camera looks through a wall from the cafe area into Rick's office. The background of the final scene, which shows a Lockheed Model 12 Electra Junior airplane with personnel walking around it, was staged using little person extras and a proportionate cardboard plane. Fog was used to mask the model's unconvincing appearance. Nevertheless, the Disney's Hollywood Studios theme park in Orlando, Florida purchased a Lockheed 12A for its Great Movie Ride attraction, and initially claimed that it was the actual plane used in the film. Film critic Roger Ebert called Hal Wallis the "key creative force" for his attention to the details of production (down to insisting on a real parrot in the Blue Parrot bar).
The difference between Bergman's and Bogart's height caused some problems. She was some two inches (5 cm) taller than Bogart, and claimed Curtiz had Bogart stand on blocks or sit on cushions in their scenes together.
Later, there were plans for a further scene, showing Rick, Renault and a detachment of Free French soldiers on a ship, to incorporate the Allies' 1942 invasion of North Africa. It proved too difficult to get Claude Rains for the shoot, and the scene was finally abandoned after David O. Selznick judged "it would be a terrible mistake to change the ending."
The original play was inspired by a trip to Europe made by Murray Burnett and his wife in 1938, during which they visited Vienna shortly after the Anschluss and were affected by the anti-Semitism they saw. In the south of France, they went to a nightclub that had a multinational clientele, among them many exiles and refugees, and the prototype of Sam.
The first writers assigned to the script were twins Julius and Philip Epstein, who, against the wishes of Warner Brothers, left at Frank Capra's request early in 1942 to work on the Why We Fight series in Washington, D.C. While they were gone, the other credited writer, Howard Koch, was assigned; he produced some thirty to forty pages. When the Epstein brothers returned after about a month, they were reassigned to Casablanca and—contrary to what Koch claimed in two published books—his work was not used. In the final Warner Bros. budget for the film, the Epsteins were paid $30,416, while Koch earned $4,200.
In the play, the Ilsa character is an American named Lois Meredith; she does not meet Laszlo until after her relationship with Rick in Paris has ended. Rick is a lawyer. To make Rick's motivation more believable, Wallis, Curtiz, and the screenwriters decided to set the film before the attack on Pearl Harbor.
The uncredited Casey Robinson assisted with three weeks of rewrites, including contributing the series of meetings between Rick and Ilsa in the cafe. Koch highlighted the political and melodramatic elements, while Curtiz seems to have favored the romantic parts, insisting on retaining the Paris flashbacks. Wallis wrote the final line, "Louis, I think this is the beginning of a beautiful friendship," after shooting had been completed. Bogart had to be called in a month after the end of filming to dub it.
Despite the many writers, the film has what Ebert describes as a "wonderfully unified and consistent" script. Koch later claimed it was the tension between his own approach and Curtiz's which accounted for this: "Surprisingly, these disparate approaches somehow meshed, and perhaps it was partly this tug of war between Curtiz and me that gave the film a certain balance." Julius Epstein would later note the screenplay contained "more corn than in the states of Kansas and Iowa combined. But when corn works, there's nothing better."
The film ran into some trouble with Joseph Breen of the Production Code Administration (the Hollywood self-censorship body), who opposed the suggestions that Captain Renault extorted sexual favors from his supplicants, and that Rick and Ilsa had slept together in Paris. Extensive changes were made, with several lines of dialogue removed or altered. All direct references to sex were deleted; Renault's selling of visas for sex, and Rick and Ilsa's previous sexual relationship were implied elliptically rather than referenced explicitly. Also, in the original script, when Sam plays "As Time Goes By", Rick remarks, "What the —— are you playing?" This line implying a curse word was removed at the behest of the Hays Office.
Wallis' first choice for director was William Wyler, but he was unavailable, so Wallis turned to his close friend Michael Curtiz. Curtiz was a Hungarian Jewish émigré; he had come to the U.S. in the 1920s, but some of his family were refugees from Nazi Europe.
Roger Ebert has commented that in Casablanca "very few shots... are memorable as shots," as Curtiz wanted images to express the story rather than to stand alone. He contributed relatively little to development of the plot. Casey Robinson said Curtiz "knew nothing whatever about story ... he saw it in pictures, and you supplied the stories."
Critic Andrew Sarris called the film "the most decisive exception to the auteur theory", of which Sarris was the most prominent proponent in the United States. Aljean Harmetz has responded, "nearly every Warner Bros. picture was an exception to the auteur theory". Other critics give more credit to Curtiz. Sidney Rosenzweig, in his study of the director's work, sees the film as a typical example of Curtiz's highlighting of moral dilemmas.
The second unit montages, such as the opening sequence of the refugee trail and the invasion of France, were directed by Don Siegel.
The cinematographer was Arthur Edeson, a veteran who had previously shot The Maltese Falcon and Frankenstein. Particular attention was paid to photographing Bergman. She was shot mainly from her preferred left side, often with a softening gauze filter and with catch lights to make her eyes sparkle; the whole effect was designed to make her face seem "ineffably sad and tender and nostalgic". Bars of shadow across the characters and in the background variously imply imprisonment, the crucifix, the symbol of the Free French Forces and emotional turmoil. Dark film noir and expressionist lighting was used in several scenes, particularly towards the end of the picture. Rosenzweig argues these shadow and lighting effects are classic elements of the Curtiz style, along with the fluid camera work and the use of the environment as a framing device.
The music was written by Max Steiner, who was best known for the score for Gone with the Wind. The song "As Time Goes By" by Herman Hupfeld had been part of the story from the original play; Steiner wanted to write his own composition to replace it, but Bergman had already cut her hair short for her next role (María in For Whom the Bell Tolls) and could not re-shoot the scenes which incorporated the song, so Steiner based the entire score on it and "La Marseillaise", the French national anthem, transforming them to reflect changing moods.
Particularly notable is the "duel of the songs" between Strasser and Laszlo at Rick's cafe. In the soundtrack, "La Marseillaise" is played by a full orchestra. Originally, the opposing piece for this iconic sequence was to be the "Horst Wessel Lied", a Nazi anthem, but this was still under international copyright in non-Allied countries. Instead "Die Wacht am Rhein" was used. The opening bars of the "Deutschlandlied", the national anthem of Germany, are featured throughout the score as a motif to represent the Germans, much as "La Marseillaise" is used to represent the Allies.
Other songs include:
- "It Had to Be You", music by Isham Jones, lyrics by Gus Kahn
- "Shine", music by Ford Dabney, lyrics by Cecil Mack and Lew Brown
- "Avalon", music and lyrics by Al Jolson, Buddy DeSylva and Vincent Rose
- "Perfidia", by Alberto Dominguez
- "The Very Thought of You", by Ray Noble, and
- "Knock on Wood", music by M. K. Jerome, lyrics by Jack Scholl, the only original song.
The piano featured in the Paris flashback sequences was sold in New York City on December 14, 2012, at Sotheby's for more than $600,000 to an anonymous bidder. The piano Sam "plays" in Rick's Café Américain, put up for auction with other film memorabilia by Turner Classic Movies and Bonhams in New York in November, 2014, sold for $3.4 million.