A Z-scheme Bi2WO6/CNT/TiO2 heterostructure was synthesized through the hydrothermal method. The photocatalysts were characterized by XRD, FTIR, SEM, EDX, TEM, UV–vis DRS, PL, and BET-BJH analyses. The photocatalytic activity of Bi2WO6/CNT/TiO2 was evaluated by the degradation of cephalexin under simulated sunlight illumination. The ternary Bi2WO6/CNT/TiO2 Z-scheme containing the optimal loading amount of 35 wt% TiO2 and 0.75 wt% CNTs, showed the best photocatalytic activity compared with pristine Bi2WO6, Bi2WO6/TiO2 and Bi2WO6/CNT/TiO2 with different mass percentage ratios. The enhanced photocatalytic activity of Bi2WO6/CNT/TiO2 was attributed to the higher specific surface area, higher visible-light adsorption spectrum, lower band gap, lower recombination of electron-hole pairs, better charge separation and higher redox ability, due to the Z-scheme construction. The optimum values of operating parameters were determined as: catalyst dose = 0.75 g/L, pH = 5, illumination time = 70 min, and cephalexin initial concentration = 20 mg/L using the central composite design. The maximum cephalexin removal efficiency in the presence of Bi2WO6/CNT/TiO2 reached 89.7% at optimum conditions. The maximum total organic carbon (TOC) removal rate was 78.9%. The photocatalytic degradation of cephalexin followed the first-order kinetic and the reaction rate by ternary composite was about 3.33 and 1.5 times, greater than those of Bi2WO6 and Bi2WO6/TiO2, respectively. The synthesized Z-scheme demonstrated an excellent chemical stability and reusability after five cyclic utilizations. According to matched Fermi level of CNTs between Bi2WO6 and TiO2, CNTs acted as electron mediator for charge transfer in the Z-scheme. Assigned to the trapping experiments, OḢ, O2−•, h+ and e- effectively improved the photodegradation process.