Cephalexin is typically used to treat bacterial infections and prevent heart valve infections. Bacterial infections that cephalexin can treat are sinus infections, irritations of the prostate, and skin infections (like cellulitis). Cephalexin is used for infants and children to treat the same infections seen in adults. It may also be given to people who are allergic to penicillin.