In 786 Ali was appointed as governor of Egypt by al-Hadi, and was re-confirmed in that office after the accession of Harun al-Rashid later that year. During his tenure in Fustat he embarked on a campaign of enjoining good and forbidding wrong, enacting measures such as prohibitions on musical instruments and wine. He also took action against recently built Christian churches, including the Church of Mary near Anba Shendua and those in the Citadel of Constantine, which he demolished despite an offer by the local Copts of fifty thousand dinars in exchange for sparing them.