Safi is located 240km south of Casablanca or 150km west of Marrakesh. By car, it will take you 2 hours to reach Safi from Casablanca and 1h20 from Marrakesh.
A cheapest and easy option if you are not in a hurry, would be to catch either one of the CTM bus from the “Marché Central” station in Casablanca (4h15 trip, departs every 3 hour) or a collective grand taxi (3h15 trip, departs hourly).
You can also access Safi by train, but it takes more time than by bus (4h45).